나는 두 개의 지시문을 가지고 있는데, 나는 아버지 파일에서 얼마나 많은 아들을 계수하고 JS 파일 다음에 표시된 것처럼 index.html에 카운터를 표시하고 싶다. 문제는 내가 정확하게 숫자를 얻지 못했다는 것이다.다른 지시어를 사용하는 지시문 - AngularJS
module.directive('directiveFather', function() {
return {
restrict: 'E',
scope: {},
controller: function ($scope) {
$scope.AllCounter = 0;
this.addCounter = function() {
$scope.AllCounter = $scope.AllCounter + 1;
}
}
}
})
module.directive('directiveSon', function() {
return {
restrict: 'E',
scope: {},
require: '^directiveFather',
link: function(scope, element, attrs, fatherCtrl){
fatherCtrl.addCounter();
}
}
}
})
<directive father>
<directive son>
</directive son>
{{AllCounter}}
</directive father>
그렇지 않으면'factory' /'service' 접근법을 사용하여 구현하십시오. – Wildhoney
팩토리/서비스 접근법의 문제점은 여러 개의 'directiveFather' 인스턴스를 지원하는 구현이 상당히 복잡하다는 것입니다. – gkalpak
다음과 같은 것을 원하지 않습니까? [http://jsfiddle.net/abzf0mem/](http://jsfiddle.net/abzf0mem/)? – Wildhoney