测试案例

.directive('testDirective', function() {
    return {
        restrict: 'E',
        template: '<p>Hello {{number}}!</p>',
        controller: function($scope, $element){
            $scope.number = "controller:"+$scope.number;
        },
        link: function(scope, el, attr) {
            scope.number = "link:"+scope.number;
        },
        compile: function(element, attributes) {
            return {
                pre: function preLink(scope, element, attributes) {
                    scope.number = "compile: pre:"+scope.number;
                },
                post: function postLink(scope, element, attributes) {
                    scope.number = "compile: post:"+scope.number;
                }
            };
        }
    }
});

controller先运行,compile后运行,link不运行

将上例中的compile注释掉,controller先运行,link后运行,link和compile不兼容

相关文章:

  • 2021-07-29
  • 2021-10-26
  • 2021-09-24
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2022-01-06
  • 2021-12-30
  • 2021-06-26
  • 2022-01-06
相关资源
相似解决方案