您的位置:首页 > 其它

controller,link,compile不同

2016-02-19 10:06 260 查看
测试案例

.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不兼容
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: