저는 새롭고 중첩 된 일부 지시어를하려고했지만 몇 가지 문제가 있습니다.angularjs에서 중첩 된 지시문을 반복합니다.
module.controller("TimelineController", ["$scope", "$compile", function ($scope, $compile) {
$scope.text = "ohoh";
$scope.elements = ["12", "13"];
console.log("Timeline Controller", arguments);
}]);
module.directive('timeline', function() {
return {
restrict: 'E',
transclude: true,
scope: true,
controller : "TimelineController",
link: function(scope, element, attrs, controller) {
console.log("linking timeline", arguments);
},
templateUrl:'templates/directives/timeline.html',
replace: true
};
});
module.directive('timelineEvent', function() {
return {
restrict: 'E',
transclude: true,
scope: true,
// controller : "TimelineController",
link: function(scope, element, attrs/*, controller*/) {
console.log("linking element", arguments);
},
templateUrl:'templates/directives/timeline_element.html',
replace: false
};
});
내 템플릿 : 여기
내 코드입니다timeline.html :
<div class="timeline">
<p>
timeline {{text}}
</p>
<div ng-repeat="element in elements">
- event {{element }}
<timeline-event ng-model="{{element}}"/>
</div>
</div>
timeline_element.html :
<div class="element">
timeline element o/ \o
</div>
내 index.html을 :
[...]
<body>
<timeline></timeline>
</body>
그리고 예상치 못한 결과 : 예상 결과는 물론 것
timeline ohoh
- event 12
- event 13
timeline element o/ \o
:
timeline ohoh
- event 12
timeline element o/ \o
- event 13
timeline element o/ \o
이 왜 성공적으로 실행 NG가 반복,하지만 중첩 된 지침 호출은 실행 일단? 루프에서 지시문을 사용할 수 없습니까?
워킹 [바이올린 (
에에 다음 라인을 변경해주십시오 http://jsfiddle.net/mrajcok/fKbtt /). 새로운 범위를 만들 필요가 없다는 것을 제외하고는 제안한 바를 따르기 때문에'scope :'행은 주석 처리됩니다. –
이 예는 "ng-controlle"이라는 오타가 있지만, 그것 없이는 끊어집니다. – iamwhitebox
정말 이상합니다. 컨트롤러를 바인드하면 작동하지 않습니다. WTF !? – schlingel