2017-05-30 51 views
0

我有一个函数只能在与ng-if和ng-repeat一起使用时调用一次。如果与ng-repeat一起使用,使用角度js调用函数一次

<td ng-if="!vm.monthView && vm.yearView=='contract-year'" nginit="vm.ContractYearBaselines()" class="baseline-data-field" ng-repeat="baselineDatum in baseline.data track by $index"restrict-to="[0-9]"> 
       {{baselineDatum}}</td> 

函数vm.ContractYearBaselines()被调用的次数的NG-重复执行......从而具有API函数调用多次.....我们可以限制函数只能与ng-repeat一起执行一次?

回答

1

您可以设置在函数内部布尔变量,并在此基础上,你可以执行它,

vm.executed = false; 
vm.ContractYearBaselines = function(){ 
    if(!vm.executed) 
    { 
     your conditions; 
    vm.executed = true; 
    } 
} 
+0

酷....它的工作..:)....谢谢.. :) @Sajeetharan – HKI345