简体   繁体   English

Angular为什么将ng-scope类放在没有附加范围的元素上

[英]Why is Angular putting the ng-scope class on an element that doesn't have a scope attached

I have a jQuery plugin that does template transformation, and an Angular directive that integrates with the plugin by calling $compile after the plugin runs on the produced DOM node: 我有一个执行模板转换的jQuery插件,以及一个Angular指令,该指令在插件在生成的DOM节点上运行后通过调用$ compile与该插件集成:

//in the link function of tiFormRender directive
element.empty();
compileForm(newForm, tiForms.frameworks(), element);
$compile(element.children())(scope);

This correctly processes directives in the subtree produced by the plugin, but for some reason it adds the class ng-scope to the compiled template: 这可以正确处理插件产生的子树中的指令,但是由于某种原因,它将ng-scope类添加到已编译的模板中:

<div ti-form-render="testForm">
    <md-content class="layout-padding ng-scope layout-row">
        <-- more DOM -->    
    </md-content>
</div>

The ti-form-render element (the original directive which does not create a scope) and the md-content element have the same scope as I would expect (verified with element.scope() ) so why did Angular attach the ng-scope class to an element that doesn't actually have a scope? ti-form-render元素(原始指令不会创建范围)和md-content元素具有与我期望的范围相同(已通过element.scope()验证),因此Angular为什么要附加ng-scope类到实际上没有作用域的元素?

ng-scope is added to any element where a scope is attached (one scope can be attached in multiple places), and since the $compile process attaches a scope to a template, it adds the class to the processed template. ng-scope被添加到附加了范围的任何元素(一个范围可以在多个位置附加),并且由于$ compile进程将范围附加到模板,因此它将类添加到已处理的模板。 It just looks a bit weird here since the scope it's attaching is the same one as the parent element, due to my hacky solution. 由于我的hacky解决方案,这里附加的作用域与父元素相同,因此在这里看起来有点奇怪。

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

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