[英]linkFn in angular directives is not working?
var $directive = angular.module('myApp', []);
$directive.directive('chandanSingh', function(){
return {
restrict: 'E',
compile:function(element, attrs){
console.log('This is complie');
},
link: function(scope, element, attrs){
console.log('This is link');
},
template: '<h4>{{title}}</h4>',
controller:function($scope){
$scope.title = "My Directive";
}
};
});
<chandan-singh></chandan-singh>
上面是我的指令和HTML指令的角度代碼。 我試圖在其中使用編譯時使用指令的“ link:linkFn”。 甚至可以對同一指令同時使用編譯和鏈接嗎?
誰能幫我這個忙嗎? 我想讓它正常工作是什么?
當您使用編譯函數時,它必須返回鏈接函數。 否則它將無法正常工作:
compile:function(element, attrs){
console.log('This is complie');
return function link(scope, element, attrs){
console.log('This is link');
},
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.