我希望能够将第二个指令电话编译为警报,我该怎么做
<div ng-app="website">
<div ng-controller="MyController">
<div phonebook="phone"> PhoneBook</div>
</div>
</div>
我希望能够将第二个指令电话编译为警报,我该怎么做
<div ng-app="website">
<div ng-controller="MyController">
<div phonebook="phone"> PhoneBook</div>
</div>
</div>
您不需要指令中的编译,phone
我相信限制是区分大小写的:
.directive('phone', function(){
return {
//HERE IS THE PROBLEM, THIS DIRECTIVE DOES NOT COMPILE
restrict: 'AC',
link: function(s,e,a){
e.bind('click', function(){
alert('clicked');
})
}
}
});
此外,我将指令添加到电话簿的模板中:
var template = '<div ng-class="{phone: number}" phone>Phone</div>';
// or '<div class="phone">Phone</div>'
我不确定它是否会在ngclass
指令中起作用,但上面的演示确实有效。