【问题标题】:Make angular directive link function as pre link?使角度指令链接功能作为预链接?
【发布时间】:2016-02-26 21:17:11
【问题描述】:

我有一个指令链接函数。默认情况下,角度链接函数是一个帖子链接函数,不是吗?如何将其作为预链接?

app.directive("textBoxCol", function () {
        return {
            require: "^grid",
            restrict: "E",
            replace: true,
            scope: {
                title: "@title",
                cssClass: "@class",
                dataField: "@field"
            },
            link: function ($scope, element, attrs, grid) {
                $scope.type = ColumnType.TextBox;
                tableControl.addColumn($scope);
            }
        };
    });

顺便说一句,它使用require。

【问题讨论】:

    标签: javascript angularjs angular-directive angular-directive-link


    【解决方案1】:

    您需要实现compile 函数并从中返回prelink 函数。

    取自 Angular 的文档 (https://docs.angularjs.org/api/ng/service/%24compile):

    compile: function compile(tElement, tAttrs, transclude) {
      return {
        pre: function preLink(scope, iElement, iAttrs, controller) { ... },
        post: function postLink(scope, iElement, iAttrs, controller) { ... }
      }
      // or
      // return function postLink( ... ) { ... }
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 2016-06-21
      • 1970-01-01
      • 2012-12-11
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      相关资源
      最近更新 更多