-1

I am loading a state with ocLazyLoad. The controller of that state has this code in the start.

$scope.test = {show: false};

and in html view I have this

<button class="btn" ng-show="test.show">Hey There</button>

Now when my view is loaded the button is not hidden. if I log {{test.show"}} it shows false. But this is not applying to button.

I tried something like this to execute controller when view is loaded

 $scope.$watch('$viewContentLoaded',
            function() {
                $timeout(function() {

                 },0);
            });

but nothing is working.

while ng-show/ng-hide is not working ng-if works perfectly. I am not able to understand why ng-show doesn't work and ng-if works. I need to use ng-show/ng-hide

Achilles
  • 519
  • 7
  • 27
  • 1
    Can u brief it with coding or make it in fiddle to analyze? – Indhu Jul 28 '17 at 05:58
  • ng-if works perfectly because it adds and removes DOM element dynamicaaly. And DOM is re-compiled in this process. But ng-show/hide just set the dispaly property none and Dom is not recompiled. – Ved Jul 28 '17 at 05:59
  • https://stackoverflow.com/questions/19177732/what-is-the-difference-between-ng-if-and-ng-show-ng-hide – Dixit Jul 28 '17 at 05:59
  • Can you provide a plunkr ? – Sherlocked Nguyen Jul 28 '17 at 06:37
  • @Ved are you suggesting I should recompile my HTML if I want to use ng-hide/ng-show and if I do where should be I doing that? – Achilles Jul 28 '17 at 06:48
  • No . I am not saying that. I am saying the limitation. Why not you are using ng-if – Ved Jul 28 '17 at 06:57
  • Because with ng-if HTML will be recompiled creating child scope in elements wrapped inside ng-if. I don't want that. I have already written code and after so much development I decided to go for lazy loading. I am not sure that replacing ng-show with ng-if every where in my code will be good idea. – Achilles Jul 28 '17 at 07:02

1 Answers1

-1

Try it.

<button class="btn" ng-hide="!test.show">Hey There</button>

  • 1
    This doesn't work and it does not make any sense also as it is almost same thing as straight using ng-show. – Achilles Jul 28 '17 at 06:40