无法在指令模板内使用角度ng-show或ng-hide

时间:2014-06-13 19:56:10

标签: angularjs angularjs-directive angularjs-scope ng-show ng-hide

网络服务返回值...如果返回的值是==' N'我想隐藏html元素。我的问题是我无法让ng-hide和ng-show在模板中工作。我查看了其他类似的问题,修复对我没有用。令人困惑的部分是,如果我查看渲染页面,ng-show语句看起来是正确的。

这是我的HTML:

<span five-star-img value="appHeader.star1"></span>
<span five-star-img value="appHeader.star2"></span>

这是我的指示:

angular.module('myApp')
.directive('fiveStarImg', function() {
    return {
       template: '<img ng-hide="{{showStar(value)}}"/>',
        restrict: 'A',
        replace: true,
        scope: {
            value: '=',
            isize: '@'
        };                  


        scope.showStar = function(value) {
            if (value == 'N') {
               return true;
            } else {
               return false;
            }
        };
    };
 });

1 个答案:

答案 0 :(得分:4)

使用{{}}ng-hide时,您不需要ng-show

template: '<img ng-hide="showStar(value)"/>'应该可以正常使用