2

I have always used ng-required with conditionals undefined like that:

<input type="text" name="var" id="var" ng-model="variable" ng-disabled="variable === undefined" ng-required="variable !== undefined">

I've never had any problems with this until now. I tried with different angularJS versions from version 1.4.9 to 1.6.2 and it happens to me the same, it enters a loop in browser because it changes the value of "variable" between the value that I have given it and undefined and it finishes failing the browser. I do not understand, I do not know why it fails now.

This is the error

4

1 回答 1

2

使用相同的范围变量来确定 ng-required (再次以自身为目标)不是一个好主意。因此,改为使用不同的范围变量来有条件地标记需要或禁用的输入,例如:

<input type="text" name="var" id="var" ng-model="variable" ng-disabled="otherVariable === undefined" ng-required="otherVariable !== undefined">

要清楚地解释为什么您的代码会导致无限期的摘要循环,需要深入研究 angularjs 框架代码,这是浪费时间

于 2017-02-14T12:03:35.830 回答