Angularjs replaceWith(otherEl)使指令功能松散
在特定事件中,在link函数中,我更改了视图html,如下所示:Angularjs replaceWith(otherEl)使指令功能松散,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,在特定事件中,在link函数中,我更改了视图html,如下所示: var html = $templateCache.get('otherTemplate')[1]; var dom = angular.element(html); element.replaceWith(dom); $compile(dom)(scope); 但有些东西坏了。示例:ngShow、ngIf指令不再工作 这是否意味着我需要以某种方式将这些指令重新绑定到新视图 这是innitial视图的外观: <div
var html = $templateCache.get('otherTemplate')[1];
var dom = angular.element(html);
element.replaceWith(dom);
$compile(dom)(scope);
但有些东西坏了。示例:ngShow、ngIf指令不再工作
这是否意味着我需要以某种方式将这些指令重新绑定到新视图
这是innitial视图的外观:
<div
some-directive-that-provides-view-data>
<h1>{{viewData.currPane}}</h1>
<div
ng-repeat="item in items"
ng-if="viewData.currPane == item.name"
the-problematic-directive="item">
</div>
</div>
{{viewData.currPane}
您不能更换一个较低的元件吗?代码正在中断,因为您正在删除以前绑定的元素。我现在就是这样使用它的,它可以正常工作。但如果可能的话,我不想要额外的html。额外的元素有什么问题?只要整个DOM树是干净的,我就看不出真正的问题。特别是在这样的情况下。如果我告诉你我在使用引导,html结构会影响样式呢?@Birowsky或者你在使用一个指令来绘制和SVG,而nodeName是至关重要的。。。