我有以下指令:
<span ng-show="{{ save_state == 'saved' }}"> Saved </span>
<span ng-show="{{ save_state == 'saving' }}"> Saving </span>
<span ng-show="{{ save_state == 'error' }}"> Error </span>
这些回调在不同的时间被调用:
var saving = function() {
$scope.save_state = "saving";
$scope.$apply();
};
var saved = function() {
$scope.save_state = "saved";
$scope.$apply();
};
var error = function(err) {
alert(err);
$scope.save_state = "error";
$scope.$apply();
};
我也有此声明用于调试
<span> {{ save_state == 'saving' }} </span>
出于某种原因,即使上面的span标记显示true
,“保存”范围标记也不会显示。 “错误”也是如此。为什么?
答案 0 :(得分:1)
这是因为您正在插入{{ }}
ng-show
指令的内容:
ng-show="{{ save_state == 'saved' }}"
ng-show
要求您提供有效的Angular Expression。:
ng-show="save_state == 'saved'"