0
중첩 된 지시문에서 팩토리 함수를 사용하는 데 문제가 있습니다.중첩 된 지시문 내에서 팩토리 함수 사용
주 코드는 컨트롤러에서 테스트 되었기 때문에 작동합니다. 모든 자바 스크립트 파일은 처음에로드됩니다. 그때는 작업 지침을 호출하는 작업 목록 지침을 호출 경로를 사용하여 todoController.js에 액세스
:
이
는 시나리오입니다.(function(angular) {
gameOnApp.directive('modalButton', function($compile) {
return {
restrict: 'A',
priority: 1001,
terminal: true,
compile: function(elm, attrs) {
elm.attr('ng-click', "modal.openModal('" + attrs.modalId + "')");
elm.removeAttr('modal-button');
elm.removeAttr('modal-id');
var fn = $compile(elm);
return function(scope){
scope.modal = Modal;
fn(scope);
};
}
}
});
gameOnApp.factory('Modal', function(){
return {
openModal: function(modalId) {
console.log(modalId);
}
}
});
})(window.angular);
그리고 내 HTML에
내가 같이 호출 :이 코드 ( modalService.js)를 구현하기 위해 노력하고있어<li>
<span modal-button modal-id="12"><i class="fa fa-edit fa-fw"></i> Edit</span>
</li>
는 HTML 응답은 다음과 같습니다
<li>
<span ng-click="modal.openModal('12')"><i class="fa fa-edit fa-fw"></i> Edit</span>
</li>
그리고 작업 Directi
gameOnApp.directive('task', function($compile, Modal) {
return {
restrict: 'E',
scope: false,
templateUrl: 'app/components/todo/taskView.html',
compile: function(elm, attrs){
return function(scope){
scope.modal = Modal;
}
}
};
});
그리고 작업 지침이 모달 지침에서 NG 클릭 기능을 인식하지 않기 때문에이 작동하지 않는 것을 알고 : 모달 코드했습니다.
어떻게 해결할 수 있습니까?