나는 내 지시문에 템플릿 내부에 템플릿을 넣어야하는 이상한 상황이 있습니다. 그 이유는 AngularJS가 속성 내부에서 ng-repeat 코드를 읽지 않기 때문입니다.지시문 내부의 템플릿
<div ng-repeat="phone in phones">
<button popover="<div ng-repeat='friend in phone.friends'>{{friend.name}}</div>"></button>
</div>
불행하게도이 때문에 팝 오버 속성 주위에 따옴표 작동하지 않습니다 이상적인 세계에서는
이 내 코드의 모습 것입니다.http://plnkr.co/edit/ZA1uA1UOlU3cCH2mbE0X?p=preview
HTML :
<div my-popover></div>
자바 스크립트 :
이 내가이 plunker에 같은 템플릿 안에 템플릿을 넣어려고 꽤 깊은 토끼 구멍 아래로 나를 이끌었다angularApp.directive('myPopover', function($compile) {
var getTemplate = function()
{
var scope = {title: "other title"};
var template = "<div> test template. title: {{title}}</div> ";
return $compile(template)(scope);
}
return {
restrict: 'A',
template: '<button class="btn btn-default" popover="{{content}}" popover-title="title">template</button>',
link: function(scope) {
scope.content = getTemplate();
}
};
})
AngularJs가 순환 참조에 대해 불평하므로 불행히도이 기능이 작동하지 않습니다. 도와주세요! (이것은 하루 종일 걸렸습니다.)
재미있을 것 같습니다. 명확히하기 위해 popover = "[[content goes here]]"안에 템플릿을 가져와야합니다. 속성은 ng-repeat를 거기에 넣을 수 없기 때문에 어려운 부분 인 것 같습니다. 이것으로 transclude가 도움이 될까요? 꽤 혼란스러운 문서를 찾고 있습니다. – Rob
popover 컨텐트가 속성 값으로 정의되지 않고 button 요소의 컨텐트로 정의 된 경우라면 도움이 될 것입니다. 그렇습니다. – Strille
다른 자습서 나 예제가 transclude를 사용하는지 확인하십시오. 이 예 (예 : http://adamalbrecht.com/2013/12/12/creating-a-simple-modal-dialog-directive-in-angular-js/)를 발견했습니다. – Strille