ng隐藏&ng显示不能仅在特定的AngularJS页面中工作
ng-hide & ng-show not working only in a particular AngularJS page
对于设备的详细信息视图页面Im正在构建,我使用了Angular的ng-show和ing-hide指令来根据设备状态颜色更改按钮显示。我使用{{item.transaction_Mode}}从数据库中获取颜色。Angular部分似乎可以正确输出"true"answers"false",但当它与ng show(如ng show="true")组合时,它就不起作用了。
HTML代码:-
颜色生成部分-
<div style="width: 30%; float: left">
<div ng-show="{{item.transaction_Mode == 'red'}}" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: red;float: left; " > </div>
<div ng-show="{{item.transaction_Mode == 'orange'}}" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: orange;float: left; " > </div>
<div ng-hide="{{item.transaction_Mode == 'red'}} || {{item.transaction_Mode == 'orange'}}" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: green;float: left; " > </div>
<h1 style="text-align: left">{{devices[whichItem].name}} - [id {{devices[whichItem].device_ID}}] </h1>
</div>
根据颜色部分的按钮显示-
<div style="width: 70%; float: left; ">
<button ng-hide="{{item.transaction_Mode == 'red'}} || {{item.transaction_Mode == 'orange'}}" style="margin-top: 20px; width: 17%; float: left; height: 46px;" type="button" data-target="modal1" class="Now waves-effect waves-light btn modal-trigger" >Now</button>
<p style="width: 3%; float: left"> </p>
<button style="margin-top: 20px; width: 17%; float: left; height: 46px;" type="button" data-target="modal2" class="Later waves-effect waves-light btn modal-trigger ">Later</button>
<p style="width: 3%; float: left"> </p>
<button ng-show="{{item.transaction_Mode == 'orange'}}" style="margin-top: 20px; width: 17%; float: left; height: 46px;" type="button" class="waves-effect waves-light btn " >Get</button>
<p style="width: 3%; float: left"> </p>
<button ng-show="{{item.transaction_Mode == 'orange'}}" style="margin-top: 20px; width: 17%; float: left; height: 46px; " type="button" data-target="modal4" class="Cancel waves-effect waves-light btn modal-trigger" >Cancel</button>
<p style="width: 3%; float: left"> </p>
<button ng-show="{{item.transaction_Mode == 'red'}}" style="margin-top: 20px; width: 17%; float: left; height: 46px; " type="button" data-target="modal3" class="Return waves-effect waves-light btn modal-trigger" >Return</button>
</div>
但同样的代码适用于另外两页,我不明白为什么它不适用。ng if或ng开关when也不起作用。任何帮助都将不胜感激,提前感谢!
打字错误。ng-if,ng-show不需要{{}}绑定到$scope数据。
所以,
<div style="width: 30%; float: left">
<div ng-show="{{item.transaction_Mode == 'red'}}" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: red;float: left; " > </div>
<div ng-show="{{item.transaction_Mode == 'orange'}}" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: orange;float: left; " > </div>
<div ng-hide="{{item.transaction_Mode == 'red'}} || {{item.transaction_Mode == 'orange'}}" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: green;float: left; " > </div>
<h1 style="text-align: left">{{devices[whichItem].name}} - [id {{devices[whichItem].device_ID}}] </h1>
</div>
应该是:
<div style="width: 30%; float: left">
<div ng-show="item.transaction_Mode == 'red'" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: red;float: left; " > </div>
<div ng-show="item.transaction_Mode == 'orange'" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: orange;float: left; " > </div>
<div ng-hide="item.transaction_Mode == 'red' || item.transaction_Mode == 'orange'" class="col s1 m1 l1 vertical-line" style="height: 100%;width: 10px; background-color: green;float: left; " > </div>
<h1 style="text-align: left">{{devices[whichItem].name}} - [id {{devices[whichItem].device_ID}}] </h1>
</div>
代替:
ng-show="{{item.transaction_Mode == 'orange'}}"
用途:
ng-show="item.transaction_Mode == 'orange'"
相关文章:
- AngularJS UI路由器不能像ng路由器那样工作
- AngularJS:ng之后,重复$scope值未按预期更新
- 防止ng重复中的重复值(AngularJS)
- 从键值结构中获取数据,并将其与AngularJS中ng重复的值进行比较
- AngularJs列表ng单击以选择选项转换
- 如何使用AngularJs禁用ng选项中的选项
- AngularJS ng开关或类似的动态值工作
- AngularJs对ng消息的自定义替换
- AngularJS ng include dons'不起作用
- 如何在所有ng点击事件AngularJS上启动一个方法
- 如何将ng选项的索引作为angularJs中的值传递给模型
- 显示&作为&在jsp中使用angularjs而不使用ng-bind-html
- 如何根据html内容使用ng类-AngularJS
- AngularJS ng选项在选择一个选项后删除了默认的空白值
- 嵌套ng重复angularjs
- 当使用select作为标签时,如何使用ng选项禁用angularjs中的选项
- 使用angularjs ng Show/ng hide显示和隐藏不同的内容
- 如何正确应用Angularjs ng repeat
- AngularJS Navigation (li ng-repeat, create header li), DOM
- ng angularjs中的重复过滤器数据不起作用