【发布时间】:2013-11-06 00:26:40
【问题描述】:
我正在使用指令将我的代码分成模板,并且我希望这些模板根据 if 条件加载。现在,当我查看网络流量时,无论是否满足 ng-if 条件,Angular 都会将所有模板发送到客户端。
<div class="container">
<ul>
<template1 ng-if="taskCategory == 'condition1'"></template1>
<template2 ng-if="taskCategory == 'condition2'"></template2>
<template3 ng-if="taskCategory == 'condition3'"></template3>
</ul>
</div>
这是我的指令模板之一的示例:
/* Directive Template */
.directive('template1', [function() {
return {
restrict: 'E',
templateUrl: 'view/templates/template1.tpl.html'
};
}])
这是预期的行为吗?它在视觉上按预期工作。但我的印象是ng-if 数据会根据条件延迟加载。还是我误会了ng-if的用法?
【问题讨论】:
标签: angularjs