javascript - ng-show 不适用于 bool 值

标签 javascript html angularjs

我正在尝试将几个 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/

相关文章:

HTML/CSS 字体颜色与 span 样式

javascript - 按日期列对可脚注行进行排序 (gg/mm/aaaa)

javascript - JSON 获取后 AngularJS 等待 View

javascript - jQuery - 设置 div 的最小高度

javascript - 如果语句不起作用 - chrome 扩展

javascript - <div> 间接更改大小时不会触发过渡

jquery - 主体背景颜色不会像其他 div 那样过渡

javascript - AngularJS 1.2 查看离开/进入动画?

javascript - 从 jquery 插件调用函数

javascript - 为什么我的 javascript 函数失败?