【发布时间】:2018-11-14 09:25:22
【问题描述】:
我想在 Angular JS 中使用 ng-if 将单词从我更改为您的。所以我使用了这段代码:
<span class="label-information-text" ng-if="changeValue" >me </span>
<span class="label-information-text" ng-if="!changeValue"> your</span>
<span class="label-edit-text pointer" ng-click="change()">CHANGE </span>
我用了这个js:
self.changeValue = true;
$scope.change = function () {
if(self.changeValue === false){
self.changeValue = true;
console.log('true');
}
else{
self.changeValue = false;
console.log('false');
}
}
【问题讨论】:
-
您是否在控制台中获得了该 console.log() 值?
-
你的控制器是写成
ng-controller="myCtrl"还是ng-controller="myCtrl as vm"?您正在使用self,我假设它是控制器本身,即var self = this;。因此,您到处都需要 controllerAs 语法。将$scope.change更改为self.change并在 HTML 中使用vm.change()等。
标签: angularjs if-statement boolean