Angularjs 角元素替换为vs“;ng if";
我正在使用以下代码研究一个包含大量指令的应用程序:Angularjs 角元素替换为vs“;ng if";,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我正在使用以下代码研究一个包含大量指令的应用程序: scope : { .. flag: '@' }, link: function(scope, element){ var template = (scope.flag === 'true') ? 'oneTemplate.html' : 'anotherTemplate.html'; $http.get(template, {cache: $templateCache}) .success(fun
scope : {
..
flag: '@'
},
link: function(scope, element){
var template = (scope.flag === 'true') ? 'oneTemplate.html' : 'anotherTemplate.html';
$http.get(template, {cache: $templateCache})
.success(function(tplContent){
element.replaceWith($compile(tplContent)(scope));
}).error(function(e){
...
});
}
与在templateUrl中指定单个模板,然后在内部使用ng if=“flag”(如果htmls非常大,则可能使用ng include)的普通指令相比,它是否有任何优势
后者对我来说似乎更简单。此指令可能是为了在需要有条件加载模板时消除大量样板代码。是的,但是ng if不能实现同样的效果吗?似乎更少的样板代码…tplContent不是动态计算的吗?它是下载的,但内容总是一样的