【发布时间】:2014-03-08 10:00:25
【问题描述】:
我想知道这个 sn-p 的工作方式是什么:
//html
<div ng-app="app">
<div ng-controller="AppCtrl">
<a my-dir ng-repeat="user in users">{{user.name}}</a>
</div>
</div>
//js
var app = angular.module('app', []);
app.controller("AppCtrl", function ($scope) {
$scope.users = [{name:'John',id:1},{name:'anonymous'}];
$scope.fxn = function() {
alert('It works');
};
})
app.directive("myDir", function ($compile) {
return {
link:function(scope,el){
el.attr('ng-click','fxn()');
//$compile(el)(scope); with this the script go mad
}
};
});
我知道这是关于编译阶段 但我不明白这一点,所以简短的解释是 非常感谢。
【问题讨论】:
标签: angularjs angularjs-directive