![](/img/trans.png)
[英]How to enable autocomplete of HTML tags within .js files for JSX for Atom?
[英]How to access HTML within custom tags in Angular JS?
我創建了一個自定義指令。
<foo>
</foo>
有什么辦法可以在這些標記中訪問html嗎? 例如
<foo>
<div>
....
</div>
</foo>
我想在我的JS中訪問此div。
您需要使用ngTransclude
https://docs.angularjs.org/api/ng/directive/ngTransclude
.directive('foo', function(){
return {
restrict: 'E',
transclude: true,
template: '<ng-transclude></ng-transclude>'
};
為什么不使用data-attr語法?
<div data-foo>
<div></div>
</div>
從評論中可以看出:您可以注入$element
並訪問或復制它的內容。
1.使用模板定義指令2.by id屬性,您可以在.js文件中追加html標記集
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.