加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – #var =“ngModel”的含义

发布时间:2020-12-17 17:51:43 所属栏目:安全 来源:网络整理
导读:我正在创建login.component.html,在此期间我创建一个输入字段,然后将其绑定到我的login.component.ts中找到的电子邮件变量.最初我写的是: input type="text" placeholder="Enter Email" id="email" [(ngModel)] = "email" name = "email" required #email="
我正在创建login.component.html,在此期间我创建一个输入字段,然后将其绑定到我的login.component.ts中找到的电子邮件变量.最初我写的是:

<input type="text" placeholder="Enter Email" id="email"
       [(ngModel)] = "email" name = "email" required #email="ngModel"/>

但在我将其更改为:

<input type="text" placeholder="Enter Email" id="email"
       [(ngModel)] = "email" name = "email" required #em="ngModel"/>

#em =“ngModel”到底发生了什么?为什么我只能使用难以置信的特定值?

解决方法

您引用的语法在 the form validation docs中提到,它们解释了:

The template variable (#name) has the value "ngModel" (always
ngModel). This gives you a reference to the Angular NgModel
directive associated with this control that you can use in the
template
to check for control states such as valid and dirty.

问题是你的@Component类上有一个名为email的属性,并且在其模板中有一个名为email的reference variable.你不能同时拥有两者,因此你看到错误:

Error: Cannot assign to a reference or variable!

重命名属性或引用变量(在您的情况下,您将后者更改为em)可以解决问题.您不仅限于“令人难以置信的特定值”,您可能已更改为任何不属于属性的有效标识符.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读