3
나는 각도가 비교적 새롭고 디버깅 후 몇 시간 동안 jquery를 추가 할 때 약간의 비호 환성을 발견했습니다. 이 지침은 그것으로 JQuery와 만 구분없이 잘 작동 : 여기jquery가 각도 지시문을 깨뜨림
/가 plnkr입니다 :
http://plnkr.co/edit/sRwqrWV1ha4Dp7lvsSAg?p=preview
var app = angular.module('plunker', []);
app.directive('dynamic', function ($compile) {
return {
restrict: 'A',
replace: true,
link: function (scope, ele, attrs) {
scope.$watch(attrs.dynamic, function(html) {
ele.html(html);
$compile(ele.contents())(scope);
});
}
};
})
app.controller('MainCtrl', function($scope, $sce, $compile) {
$scope.trustedHtml = $sce.trustAsHtml('<button ng-click="testAlert()">Submit</button>');
$scope.testAlert = function() {
alert('testing');
};
});
어쩌면 내가 질문을하지 않습니다
이
은 더 나은 솔루션의 일종이다. 하지만 왜 trustAsHtml을 사용하십시오. 당신의 덩어리가 그것없이 잘 작동합니다. Jquery 선물 여부. http://plnkr.co/edit/vPBFWfKV7toPquQFtozH?p=preview – mainguy