angularjs - AngularJS 指令前链接和后链接功能可以自定义吗?

标签 angularjs angularjs-directive

我看过很多对 AngularJS 的引用 链接前和链接后功能 在有关 AngularJS 的文献中。

但是,我不确定这些是否可以自定义或在框架内部。

换句话说,作为一个 AngularJS 开发者,我可以提供我自己的 前后链接功能到我的自定义指令?

最佳答案

是的,你可以,根据@Mikke 的回答。总结起来,链接函数的声明方式有四种:

  • 从内部 compile指定两者 preLinkpostLink明确的功能:
    compile: function compile(tElement, tAttrs, transclude) {
      return {
        pre: function preLink(scope, iElement, iAttrs, controller) { ... },
        post: function postLink(scope, iElement, iAttrs, controller) { ... }
      }
    }
    
  • 从内部 compile仅返回 postLink隐含地:
    compile: function compile(tElement, tAttrs, transclude) {
      return function postLink( ... ) { ... }
    }
    
  • 从内部 link指定两者 preLinkpostLink明确地:
    link: {
      pre: function preLink(scope, iElement, iAttrs, controller) { ... },
      post: function postLink(scope, iElement, iAttrs, controller) { ... }
    }
    
  • 来自于 link使用 postLink隐含地:
    link: function postLink( ... ) { ... }
    
  • 关于angularjs - AngularJS 指令前链接和后链接功能可以自定义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22105336/

    相关文章:

    javascript - 使用 Angular JS 中的 CKEditor 内容更新文本区域值

    javascript - 如何在指令中访问子 Controller 和父 Controller ?

    javascript - 在之前的 $http 完成后使用 $http

    javascript - AngularJS 文件浏览器

    javascript - 如何使 AngularJS 指令处于事件状态

    javascript - 使用 $compile 以编程方式添加指令并从范围传递数据,

    javascript - 如何在 AngularJS 自己的指令中使用 ng-class 和函数?

    javascript - 拦截点击链接

    javascript - 使用 AngularJS 的 FILTER 函数计算过滤器内重复元素的总和

    javascript - 为什么 Plunker 使用 AngularJS 时会出现 404 错误?