在 angular 中,为什么我的 ng-shows 没有更新以反映当前范围?
In angular, why are my ng-shows not updating to reflect the current scope?
我在另一个 ng-repeat 中的 ng-repeat 中有一个 ng-show。那个 ng-show 里面有一个按钮。当我单击该按钮时,我的范围已正确更新,但 ng-show 在我刷新页面之前不会更改。
模板:
<div ng-repeat="quest in quests">
<p ng-show="{{quest.progress === 0}}">You and goat have found a castle.</p>
<p ng-repeat="step in quest._steps">
<span ng-show="{{quest.progress === step.order}}">You are here</span>
<span ng-show="{{quest.progress + 1 === step.order}}">Goat Says: {{step.flavorText}} {{step.description}}<button ng-click="nextStep(quest)">Step Complete!</button>
</span>
</p>
控制器:
$scope.nextStep = function(currentQuest, i) {
currentQuest.progress++;
console.log('$scope.quests', $scope.quests);
questService.editQuest(currentQuest._id, currentQuest)
.then(function(response) {
});
};
所以现在,当我点击时,我的数据库正在正确更新,$scope.quests 的 console.log 显示了一个正确更新的任务对象(我不太明白,因为我' m 递增 currentQuest.progress 而不是 $scope.quests[$index] 或其他什么,但由于范围已更新我不在乎),那么到底为什么不显示和隐藏正确的 ng-shows ??
因为你用的是插值大括号{{}}
... ng-show
直接读取表达式。这对于许多核心指令都是一样的。
插值大括号用于将文本打印到 dom
改变
ng-show="{{quest.progress === 0}}"
到
ng-show="quest.progress === 0"
我在另一个 ng-repeat 中的 ng-repeat 中有一个 ng-show。那个 ng-show 里面有一个按钮。当我单击该按钮时,我的范围已正确更新,但 ng-show 在我刷新页面之前不会更改。
模板:
<div ng-repeat="quest in quests">
<p ng-show="{{quest.progress === 0}}">You and goat have found a castle.</p>
<p ng-repeat="step in quest._steps">
<span ng-show="{{quest.progress === step.order}}">You are here</span>
<span ng-show="{{quest.progress + 1 === step.order}}">Goat Says: {{step.flavorText}} {{step.description}}<button ng-click="nextStep(quest)">Step Complete!</button>
</span>
</p>
控制器:
$scope.nextStep = function(currentQuest, i) {
currentQuest.progress++;
console.log('$scope.quests', $scope.quests);
questService.editQuest(currentQuest._id, currentQuest)
.then(function(response) {
});
};
所以现在,当我点击时,我的数据库正在正确更新,$scope.quests 的 console.log 显示了一个正确更新的任务对象(我不太明白,因为我' m 递增 currentQuest.progress 而不是 $scope.quests[$index] 或其他什么,但由于范围已更新我不在乎),那么到底为什么不显示和隐藏正确的 ng-shows ??
因为你用的是插值大括号{{}}
... ng-show
直接读取表达式。这对于许多核心指令都是一样的。
插值大括号用于将文本打印到 dom
改变
ng-show="{{quest.progress === 0}}"
到
ng-show="quest.progress === 0"