Angular Scoping With ng-if
Background
When using Angular 1.x, you might have a simple form that looks like this:
However, if you ran this code and clicked ‘Save’, $scope.someOtherInput
would be undefined.
WTF is going on?
The issue is that ng-if
creates its own scope, so someOtherInput
isn’t
defined on your usual controller scope.
Workaround
Fortunately the workaround is simple. Just use the controllerAs syntax, which is generally useful for various other reasons.