AngularJS:在编译前获取指令的html内容
AngularJS: Get html content of a directive before compile
我正在创建一个指令,当用户点击按钮时显示一个模态:
指令模板:
<button ng-click="showModal()">Show Modal</button>
指令的用法:
<modal-btn>
<div id="modal-content">
<p>This is the modal content that I want to render in the Modal {{someModel}}</p>
</div>
</modal-btn>
所以在我编译指令之前,我需要抓取内容,显示按钮,当用户单击按钮时,我显示包含<div id="modal-content">....
如何在编译指令并将其替换为模板之前获取指令内部内容
嗯…这实际上是一个非常有趣的模式使用modal与本地内容像这样。
所以,要完成所有你需要的是角指令的transclude
选项。有一篇关于变性的好文章。