2
접을 수있는 패널처럼 동작하는 간단한 지시문을 만들었습니다.
이 지시어의 내용에는 ng-repeat 템플릿을 패널로 만들 항목 템플릿이 추가됩니다. 템플릿 자체에 ng-repeat가있는 경우 모두 모든 데이터 소스 항목에 액세스 할 수 있지만 잘 작동하지는 않습니다. http://plnkr.co/edit/7mhlO3GJTmFpyF1wrVYg
당신은 심지어 정적 데이터 자식 NG가 반복 제대로 컴파일되는 것을 볼 수 있습니다
여기 데모입니다.
app.directive('collapsible', ['$compile', function($compile) {
return {
restrict: 'A',
scope: {
srcData: "=ngModel"
},
link: function($scope, $element){
// Extract the item template from the directive content
var children = $element.children();
// Wrap the item template with the repeater
var template = angular.element('<div ng-repeat="item in srcData"></div>');
template.append(children);
var cfn = $compile(template); // compile
cfn($scope); // attach the scope
$element.html(template); // add it back to the directive content
$element.on('click', 'h3 .button', function(e){
e.stopPropagation();
var $this = $(this);
if($this.hasClass('close')){
$scope.srcData.splice($this.scope().$index, 1);
$scope.$apply();
}
});
$element.on('click', 'h3', function(e){
e.stopPropagation()
var $this = $(this);
$(this).next('div').toggle();
});
}
};
}]);
당신이 내게되는 HTML 보여줄 수 :
다음 지시어 코드가 작동 이제? 나는 'text/ng-template'으로 내부 내용을 래핑하는 방법을 이해하지 못한다. – tom10271