0

lately I have a pretty significant problem with ng-view and ng-if.Suppose there is a dropdown with two elements (element one and element two).The two elements change a property on rootScope.

I have two more items at another location (div-container, container one and two containers). These are displayed by ng-show - container one at element one and container at element two.

As soon as I click the one element one time and the property of the rootScope changes and then I reload the page, the two containers are alternately displayed without that I do something.

I have several watchers, seveleral ng-cloaks and use the routing using ng-view. I would also like to mention that the application is relatively large. Most often, the problem occurs on Android, presumably on iOS.

030
  • 10,842
  • 12
  • 78
  • 123
Heddy
  • 1
  • Welcome to StackOverflow! Can you post a minimal example of your code that demonstrates the problem? It is much easier to debug code that can be seen. – gariepy Mar 31 '16 at 22:25

1 Answers1

0

As soon as I click the one element one time and the property of the rootScope changes and then I reload the page, the two containers are alternately displayed without that I do something.

Did you mean the other two containers just show up for a second and then disappear? If that is the case then I think the condition you are providing inside ng-show is true at the loading time so they appear for a while before the condition changes and then they disappear.

You have to make sure the condition for ng-show is initially false.

Roy
  • 1,939
  • 1
  • 14
  • 21
  • scope-property: "value". Container1 is displayed if "value" is false. Container2 is displayed if "value" is true. "value" is initally false. So container1 is initially displayed. If I change the "value" to true, container1 is hidden and container2 is displayed. The "value" are stored in a cookie - name it "c_value". After page is loaded I check if there is a cookie named "c_value" and I check if it is "true" (here string) and the boolean will fill "value". After I reload the page, the "value" changes to true (cause of the cookie) then changes back to false, changing back to true and so on. – Heddy Apr 01 '16 at 13:37
  • So you are saying that the value toggles **after** you set the initial value from cookie? – Roy Apr 03 '16 at 01:14
  • Correct. But I think I have found the solution: I've used "$timeout" very often to update the view, probably too often I think. After reading many articles I use it only if I will make a jQuery-animation with a "complete-function" or something similar, cause of updating scope-properties outside of the "angular-environment". anyway thank you for your effort – Heddy Apr 08 '16 at 15:10