在 Angular 中,我可以从模板 url 中嵌入内容吗?
In Angular, can I transclude content from a template url?
我想从模板 url 中嵌入内容,而不是从指令标签的主体中嵌入内容。
以模态为例,您可能会看到需要模态指令为模态包装器标记声明模板 url,但是对于嵌入的内容而不是从指令中获取该内容标签(某些模式可能有大量标记)我想使用模板 url 来提供转换后的内容。因此为组件提供了一个更清晰的抽象层。
即
homeView.html
<my-modal transclude-content="profile"></my-modal>
modalDirective.js
app.directive('modal', function() {
return {
templateUrl: 'app/shared/modalView.html',
// some nifty way to transclude content from say 'app/shared/partials/' + attr.transcludeContent + '.html
};
});
modalView.html
<div class="modal">
<div class="modal-controls">
<span class="minimize">-</span>
<span class="close">x</span>
</div>
<div class="modal-body" ng-transclude>
</div>
</div>
答案很简单!
嵌套你的指令!!
<modal-window>
<user-profile></user-profile>
</modal-window>
我想从模板 url 中嵌入内容,而不是从指令标签的主体中嵌入内容。
以模态为例,您可能会看到需要模态指令为模态包装器标记声明模板 url,但是对于嵌入的内容而不是从指令中获取该内容标签(某些模式可能有大量标记)我想使用模板 url 来提供转换后的内容。因此为组件提供了一个更清晰的抽象层。
即
homeView.html
<my-modal transclude-content="profile"></my-modal>
modalDirective.js
app.directive('modal', function() {
return {
templateUrl: 'app/shared/modalView.html',
// some nifty way to transclude content from say 'app/shared/partials/' + attr.transcludeContent + '.html
};
});
modalView.html
<div class="modal">
<div class="modal-controls">
<span class="minimize">-</span>
<span class="close">x</span>
</div>
<div class="modal-body" ng-transclude>
</div>
</div>
答案很简单!
嵌套你的指令!!
<modal-window>
<user-profile></user-profile>
</modal-window>