相关疑难解决方法(0)

AngularJS:无论ng-if条件如何,加载指令模板

我正在使用Directives将我的代码分成模板,我希望这些模板基于if条件加载.现在,当我查看网络流量时,Angular会将所有模板发送到客户端,无论ng-if条件是否满足.

<div class="container">
    <ul>
        <template1 ng-if="taskCategory == 'condition1'"></template1>
        <template2 ng-if="taskCategory == 'condition2'"></template2>
        <template3 ng-if="taskCategory == 'condition3'"></template3>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

以下是我的一个指令模板的示例:

/* Directive Template */
.directive('template1', [function() {
    return {
        restrict: 'E',
        templateUrl: 'view/templates/template1.tpl.html'
    };
}])
Run Code Online (Sandbox Code Playgroud)

这是预期的行为吗?它按预期可视化工作.但我的印象是ng-if数据会根据条件延迟加载.或者我误解了如何使用ng-if

angularjs

5
推荐指数
1
解决办法
4304
查看次数

标签 统计

angularjs ×1