加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何比较ng-show中的一个字符串在一个customdirect

发布时间:2020-12-17 07:44:48 所属栏目:安全 来源:网络整理
导读:尝试在其中使用带有ng-show语句的指令.基本上它检查一个字符串的值,它是我的’names’jsonarray中的status_p1属性: ng-show="name.status_p1==working" 该指令定义为: app.directive('radioButton',function(){ return { restrict: 'E',replace: 'true',te
尝试在其中使用带有ng-show语句的指令.基本上它检查一个字符串的值,它是我的’names’jsonarray中的status_p1属性:
ng-show="name.status_p1==working"

该指令定义为:

app.directive('radioButton',function(){
  return {
    restrict: 'E',replace: 'true',template: '<table border="2px">' +
    '<tr><td>{{name.name}}</td><td>Working</td><td><img src="http://www.iconshock.com/img_jpg/REALVISTA/general/jpg/256/cross_icon.jpg" alt="img1" id="imgworking" ng-show="name.status_p1!=working"><img src="http://png-1.findicons.com/files/icons/2198/dark_glass/128/camera_test.png" alt="img2" ng-show="name.status_p1==working"></td></tr>' +
    '</table>'
  };
})

我的主页中的控制器名称如下所示:

app.controller('MainCtrl',function($scope) {
 $scope.names = [
    {
      name: 'couple 1',status_p1: 'working',status_p2: 'retired'
    }

  ]
});

最后的主页:

<body ng-controller="MainCtrl">
    <div ng-repeat="name in names">
      <radio-button></radio-button>
    </div>
</body>

目前显示一个十字架,它应该显示一个支票/勾号.我期待的条件评估为TRUE,因为status_p1属性等于“工作”.如何修改这个ng-showstatement以使字符串比较工作?
plunkr链接:http://plnkr.co/edit/3VdsbsSHpkNJFVnvkmOW?p=preview

表达方式
ng-show="name.status_p1==working"

将name.status_p1与当前作用域的工作属性进行比较,这在您的情况下未定义.您需要的是将其与文字字符串“工作”进行比较.

ng-show="name.status_p1=='working'";

修改Plunkr

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读