1

I would like to be able to set ng-show off a variable I set on the scope variable within the link function of an Angular customer directive.

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

Unfortunately, when I do this it doesn't work as expected. If I set scope.showme=true, then my directive is hidden. If I set it =false then it is shown. How am I screwing this up?

honkskillet
  • 3,007
  • 6
  • 31
  • 47

1 Answers1

2

ng-show needs an expression not the value of an expression, so remove interpolation {{}} from the expression.

Do:

 template: <div ng-show="showme"> hello </div>,
PSL
  • 123,204
  • 21
  • 253
  • 243