假设我有一个名为 my-directive
的指令.
如何访问或操作指令代码中指令标记之间的文本,如下所示:
<my-directive> Custom Text <my-directive>
我的指令代码:
app.directive('myDirective', function() {
return {
...
template: '<div>...Custom Text somewhere inside div... </div>'
};
);
最佳答案
使用ng-transclude
模板中的指令。
.directive('myDirective', function() {
return {
transclude: true,
template: '<div><ng-transclude></ng-transclude></div>
}
});
将之前的内部内容移动到模板中 ng-transclude 所在的位置。
关于angularjs - 指令标签之间的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27266595/