简体   繁体   English

是否可以为DOM元素而不是整个文档初始化Angular.js?

[英]Is it possible to initialize Angular.js for DOM element instead of for whole document?

I'm making relatively complex jQuery UI plugin and I'm thinking about using Angular to simplify development. 我正在制作相对复杂的jQuery UI插件,正在考虑使用Angular简化开发。

But as I know, Angular initializes itself using whole document. 但是据我所知,Angular使用整个文档进行初始化。

Is it possible, to initialize Angular.js and make it compile templates in bounds of chosen DOM element? 是否可以初始化Angular.js并使其在所选DOM元素的边界内编译模板?

The ng-app directive determines the root element of the Angular "application." ng-app指令确定Angular“应用程序”的根元素。 I think anything outside the tree rooted in that element is left alone. 我认为,植根于该元素的树之外的任何事物都将被留下。

Yes It is possible Angular starts compilation where it gets the ng-app attributes. 是是Angular可能在获得ng-app属性的情况下开始编译。

Use ng-app attribute on your dom where you want angular to be used rather than inside html or body. 在要使用角度的dom上使用ng-app属性,而不是在html或body内使用。

Ex 防爆

<html>
  <body>
    <!--html to be compiled by angularjs-->
    <div ng-app="yourAngularApp">
    </div>
 <!--html code outside of angular access-->
  <div>This element will not be compiled by angularjs</div>
  </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM