Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS-ngRequired和conditional undefined的问题_Angularjs_Ng Required - Fatal编程技术网

AngularJS-ngRequired和conditional undefined的问题

AngularJS-ngRequired和conditional undefined的问题,angularjs,ng-required,Angularjs,Ng Required,我一直使用ng required和未定义的条件: <input type="text" name="var" id="var" ng-model="variable" ng-disabled="variable === undefined" ng-required="variable !== undefined"> 到现在为止,我从来没有遇到过任何问题。我尝试了不同的angularJS版本,从1.4.9版到1.6.2版,但同样的情况发生在我身上,它在浏览器中进入了一个循环,因为

我一直使用ng required和未定义的条件:

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

到现在为止,我从来没有遇到过任何问题。我尝试了不同的angularJS版本,从1.4.9版到1.6.2版,但同样的情况发生在我身上,它在浏览器中进入了一个循环,因为它在我给定的值和未定义的值之间更改了“variable”的值,并且浏览器失败。我不明白,我不知道为什么它现在失败了


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

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


要清楚地解释代码导致不确定摘要循环的原因,需要深入研究angularjs框架代码,这是在浪费时间

您介意添加一个演示吗?为什么会有
==
ng required中
不应该是
=?这是真的,如果我使用undefined,那么字段将被禁用,我没有注意到在这种情况下,它变成了undefined变量。然后我将使用条件null。我需要从后面知道哪些字段是启用的,哪些是必需的,我需要一种方法来区分它们,我已经想到了未定义的字段,但是我发现它是不可行的。当变量
变量
未定义的
时,设置
disabled
属性有什么意义?这意味着一旦用户清空输入字段,您的输入字段将被禁用。当您删除
ng disabled
指令时,它应该可以正常工作。虽然remove ngDisabled问题仍然存在,但我已经尝试过了。是的,如果您使用另一个变量,则没有问题,但为什么使用相同的变量和未定义的变量会出现这种情况?如果我使用任何其他比较,它不会循环。