【发布时间】:2016-02-03 00:57:27
【问题描述】:
我需要在指令中使用动态模板。我为此使用 replaceWith() 方法:
var template;
switch (scope.type) {
case 'type1':
template = angular.element('<div>Type1</div>');
break;
case 'type2':
template = angular.element('<div>Type2</div>');
break;
}
element.replaceWith(template);
在范围内添加新元素之前可以正常工作。当 $scope 更新时,我看到容器中的两个元素:
<some-content ng-repeat="content in contents" type="content.type" class="ng-scope ng-isolate-scope"></some-content>
<div class="test">Type1</div>
<some-content ng-repeat="content in contents" type="content.type" class="ng-scope ng-isolate-scope"></some-content>
<div class="test">Type2</div>
【问题讨论】:
标签: angularjs angularjs-directive