我正在将响应数据分配给$scope但带有ng-show的div仍然隐藏。我是 angularjs 的菜鸟,怎么了??
else {
debugger;
$scope.exception = data.exception; //data arrives correctly
和 HTML
<div class="error-text" ng-show="exception.code">
但它不起作用,控制台上没有显示错误
ng-show
指令对真值或假值进行操作。
如果exception
缺少代码属性,则该元素将不会自行显示。
尝试:
̶<̶d̶i̶v̶ ̶c̶l̶a̶s̶s̶=̶"̶e̶r̶r̶o̶r̶-̶t̶e̶x̶t̶"̶ ̶ ̶n̶g̶-̶s̶h̶o̶w̶=̶"̶e̶x̶c̶e̶p̶t̶i̶o̶n̶.̶c̶o̶d̶e̶"̶>̶
<div class="error-text" ng-show="exception">
exception = {{exception}}
</div>
有关详细信息,请参阅
- AngularJS ng-show 指令 API 参考
'ng-show' 适用于布尔值,因此您只需设置$scope.exception.code = true;,确保 exception 中的对象具有名为"code"的布尔键。
所以你的JS代码将是这样的:
else {
debugger;
$scope.exception = data.exception;//data arrives correcly
$scope.exception.data = true;
}