我有指令
app.directive("dir", function($compile, $sce){
return{
restrict: "E",
link: function(scope, element, attr){
scope.$watch('content',function(){
var html = $sce.trustAsHtml(attr.content);
scope.alabala = $compile(html)(scope);
},true);
},
template: "
}
});
控制器:
function MainController($scope, $http, customService, $location, $sce, $compile){
$scope.init = function(){
customService.get().success(function(data) {
var html = $sce.trustAsHtml(data);
$("#dir").attr("content", data);
});
};
}
在索引页面上,我有:
每当包含不同的html时,我的自定义服务都会返回
Click me
我想做的是每次在指令的内容中推送不同的值以对其进行编译并将其放入html并处理控制器中的click函数时。因为我是AngularJS的新手,所以一段时间以来一直在努力解决这个问题。请帮忙。