I'm using an ad-hoc ngIf
directive for Angular 1.0.3 acquired from this SO answer.
// effectively
app.directive("ngIf", function () {
return function(scope, element, attrs) {
if (scope.$eval(attrs.ngIf)) {
} else {
element.replaceWith(' ');
}
}
}
});
The element actually gets removed. If the element has ng-model
(and possibly other directives) Angular will complain.
<input ng-if="msg == 'foo'" ng-model=msg>
If msg
is not foo
, we get
Error: No controller: ngModel
This most likely has to do with the element being removed when ngModel is evaluated.
Is there any way to rewrite the ngIf
directive so that the error does not occur?