1
부모 범위에서 ng-repeat로 부분적으로 채워진 지시문이 있고 수신기는 postLink
에 연결됩니다. 그러나 내용이 중첩되어 있기 때문에 링크 시간에 사용할 수 없거나 보간되지 않습니다.각도 : 반투명 템플릿 연결
템플릿 :이
<script type="text/ng-template" id="directive.html">
<div>list item count: {{ count }} (should be {{2 + items.length }})</div>
<div>Transcluded content: <span ng-transclude></span></div>
</script>
<div ng-controller="Ctrl">
<ul frag>
<li ng-repeat="item in items">{{ item }}</li>
<li>4</li>
<li>5</li>
</ul>
</div>
코드 :이 경우
app.directive("frag", function ($http) {
return {
restrict: 'A',
transclude: true,
templateUrl: 'directive.html',
link: function (scope, element, attrs) {
scope.count = element.find("li").length;
console.log(element);
},
controller: function ($scope) {
$scope.foundB = false;
}
};
});
, 목록 항목 수가 끝나는
나는 보여주기 위해 함께 JSFiddle example를 던져했습니다 예상되는 5보다는 오히려 2로 예상된다.
누구나 내가 어떻게이 작업을 할 수 있었는지 알 수 있습니까? 내가 관찰 할 수있는 일종의 사후 전출 사건을 발견 할 것으로 기대 했었지만, 그때 그 연계 만 수행 할 수는 있었지만 발견 할 수 없었다.
따 - 나는 마지막으로'$의 timeout'를 사용하여 저장했다 리조트! (a) 나는 뻔한 것을 놓쳤거나, (b) 더 깔끔한 것이있다. – Dave