我有一个指令
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时,我的自定义服务都会返回
我想要做的是每当我在我的指令的内容中推送一个不同的值来编译它并将它放在我的html中并从我的控制器处理click函数时.因为我是AngularJS的新手,所以我一直在努力解决这个问题.请帮忙.