如何在angularjs中编译已编译的模板

时间:2013-05-17 17:03:37

标签: templates angularjs compilation directive

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

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

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

1 个答案:

答案 0 :(得分: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指令,但上述演示确实有效。