2015-02-08 28 views
1

我希望能夠在Angular客戶指令的鏈接函數內的範圍變量中設置一個變量的ng-show。從鏈接函數中指令範圍的變量設置角度的ng-show

angular.module('myApp') 
    .directive('testDir', function() { 
    return { 
     template: <div ng-show="{{showme}}"> hello </div>, 
     link: function (scope, element, attrs) { // 
     scope.showme=true; 
    } 
    }); 

不幸的是,當我這樣做時,它不能按預期工作。如果我設置scope.showme = true,那麼我的指令是隱藏的。如果我將它設置爲false,則顯示它。我怎麼搞砸了?

回答

2

ng-show需要一個表達式不是表達式的值,所以從表達式中刪除插值{{}}

務必:

template: <div ng-show="showme"> hello </div>,