Model does not update within ng-if

stofl picture stofl · Nov 19, 2013 · Viewed 17.5k times · Source

I've got a strange behavior in an angular application and I don't know if that's a bug or a known limitation:

http://jsfiddle.net/78R52/

I would expect that clicking one of the buttons would set foo = true, but clicking the first button (within the ng-if="!foo") doesn't change the model.

Tested version is 1.2.1.

Answer

thebenedict picture thebenedict · Nov 19, 2013

ng-if has its own scope, so you need to use:

<br/><button ng-click="$parent.foo = true;">Show foo</button>

Updated fiddle: http://jsfiddle.net/78R52/1/