The solution provided above has successfully addressed the issue. You can view my working example on Plunker by following this link: http://plnkr.co/edit/ZdL441bBmQToGZn4gfQt?p=preview. Additionally, I would like to add:
According to the official AngularJS documentation, using ng-if
creates its own scope which inherits from the parent scope through prototypal inheritance.
The scope created within ngIf inherits from its parent scope using prototypal inheritance.
In essence, when referencing a value from the parent scope, only the value itself is copied for primitive types (such as string
, integer
, boolean
, etc.) and not the reference (or pointer
). This results in one-way reference rather than two-way. To achieve two-way binding, it is recommended to always use a JavaScript object {attribute: value}. This is why using a dot notation (.
) is preferred.
I highly recommend reading this informative article about scopes that is worth 20 minutes of your time: https://github.com/angular/angular.js/wiki/Understanding-Scopes
I hope this explanation proves helpful to you :)