버튼을 클릭 한 후 아래 코드가 작동하지 않습니다. 지시어가 다시 컴파일되지 않은 것 같습니다. 아무도 나를 도와 줄 수 없어!ng-click 후 각도 지시문이 컴파일되지 않음
HTML은 :
<button ng-click="run()">click</button>
<p>Hello {{name}}!</p>
<customdir filterby="name"></customdir>
마찬가지의 코드는 여기 http://plnkr.co/edit/OQqLeUIoFNhkqSoeIdyM?p=preview 찾을 수 있습니다.
자바 스크립트 :
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.run = function() {
$scope.name = 'goal';
};
});
app.directive('customdir', function($compile) {
var getTemplate = function(filterby) {
switch (filterby) {
case 'World':
return '<div class="col-lg-1" id="ready">' +
'<img ng-src="http://plnkr.co/img/plunker.png" style="height: 35px; width: 35px; margin-left: 70px; margin-bottom: 3px" />' +
'</div>';
case 'goal':
return '<b>tttttt !!</b>';
default:
return '<b>Error !!</b>';
}
}
return {
restrict: 'E',
scope: {
filterby: '='
},
link: function(scope, element, attrs) {
var el = $compile(getTemplate(scope.filterby))(scope);
element.replaceWith(el);
}
};
});