我正在尝试将几个 div 与服务值绑定(bind)"
<body ng-controller="PageConfigurationController">
<label>{{TopLeftPage}}</label><label>{{TopRightPage}}</label>
<label>{{ButtomRightPage}}</label><label>{{ButtomLeftPage}}</label>
<div ng-show="{{TopLeftPage}}"><h1>Div1 </h1></div>
<div ng-show="{{TopRightPage}}"><h1>Div2 </h1></div>
<div ng-show="{{ButtomRightPage}}"><h1>Div3 </h1></div>
<div ng-show="{{ButtomLeftPage}}"><h1>Div4 </h1></div>
标签可以很好地显示 bool 值,但默认情况下所有 div 都是隐藏的,无论它是真还是假。
最佳答案
<div ng-show="TopLeftPage"><h1>Div1 </h1></div>
<div ng-show="TopRightPage"><h1>Div2 </h1></div>
<div ng-show="ButtomRightPage"><h1>Div3 </h1></div>
<div ng-show="ButtomLeftPage"><h1>Div4 </h1></div>
从你的 ng-show 和 js 中移除花括号
$scope.TopLeftPage=true;
$scope.TopRightPage=true;
$scope.ButtomRightPage=true;
$scope.ButtomLeftPage=true;
//true 表示显示,false 表示隐藏
关于javascript - ng-show 不适用于 bool 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35864140/