0

我希望能够将第二个指令电话编译为警报,我该怎么做

<div ng-app="website">
    <div ng-controller="MyController">    
        <div phonebook="phone">  PhoneBook</div>
    </div>
</div>

http://jsfiddle.net/x3azn/GzsQJ/3/

4

1 回答 1

1

您不需要指令中的编译,phone我相信限制是区分大小写的:

http://jsfiddle.net/GzsQJ/4/

.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指令中起作用,但上面的演示确实有效。

于 2013-05-17T18:42:43.037 回答