【发布时间】:2016-01-05 18:16:59
【问题描述】:
对于我正在构建的设备的详细信息视图页面,我使用了 Angular 的 ng-show 和 ng-hide 指令来根据设备状态颜色更改按钮显示。我使用 {{item.transaction_Mode}} 从数据库中获取颜色。 Angular 部分似乎可以正常工作,因为它可以正确输出“true”和“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-switch-when 也不起作用。 任何帮助将不胜感激,在此先感谢!
【问题讨论】:
-
您是否也在此页面中包含了控制器?
-
尝试使用
ng-if来克服它! -
你有让这些元素可见的 CSS 样式吗?
ngShow和ngHide使用display: none -
去掉花括号。例如:将 ng-show="{{item.transaction_Mode == 'orange'}}" 更改为 ng-show="item.transaction_Mode == 'orange'"
-
我的控制器如下 - homeCtrls.controller('detailsCtrl', ['$scope', '$http', '$routeParams', function ($scope, $http, $routeParams) { $http.get('webapi/devices').success(function (data) { $scope.devices = data; $scope.whichItem = $routeParams.itemId; });
标签: javascript jquery angularjs ng-hide