Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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不工作_Angular - Fatal编程技术网

Angularjs不工作

Angularjs不工作,angular,Angular,我有两个输入type=“text”。在提交表格之前,至少应填写其中一份。代码如下 <form class="form-horizontal" #formname = "ngForm"> <div class="form-group"> <input class="form-control" id="textToysKeywords" [(ngModel)]="toysKeywords" type="text" name = "tKeywords"

我有两个输入
type=“text”
。在提交表格之前,至少应填写其中一份。代码如下

<form class="form-horizontal" #formname = "ngForm">

   <div class="form-group">
      <input class="form-control" id="textToysKeywords" [(ngModel)]="toysKeywords" type="text" name = "tKeywords" required ="'!(clothKeywords.Length)'" #toysKeywordsVar="ngModel"> 
 </div>
 <div class="form-group">
      <input class="form-control" id="textClothKeywords" [(ngModel)]="clothKeywords" type="text" name = "cKeywords" required ="'!(toysKeywordsVar.Length)'" #clothKeywordsVar="ngModel"> 
 </div>

<button class="btn" type="submit" [disabled] = "!formname.valid" (click)="clickMethod()">

</form>


这是行不通的。除非我在两个文本字段中都输入一些值,否则该按钮将被禁用。如何更正此问题?

问题在于,您键入的
Length
是大写的L,因此它将始终返回未定义的值,与字段值无关,并且您缺少必需的括号(
[]
),并将不需要的单引号放在括号中

改变

required="'!(clothKeywords.Length)'"
为此:

[required]="!(clothKeywords.length)"

使用ng change检查输入字段中的一个字段是否有效。在此基础上,您可以启用/禁用该按钮。这将抛出未定义的“无法读取”属性“长度”。似乎,因为我试图在呈现第一个输入字段时计算第二个textbox.length,所以它会抛出错误!我试图通过将条件更改为[required]=“!(textClothKeywords&&clothKeywords.length)来解决这个问题,但它仍然不起作用!有什么想法吗?将控制器上的ngModel初始化为空字符串。同时显示控制器代码。