angular - 模板引用变量给出_r0不是函数错误
问题描述
我有一个搜索字段,当按下回车键时会触发搜索方法。
<mat-form-field class="search-field">
<mat-label>Search</mat-label>
<input type="text" (keyup.enter)="search($event)" matInput #search>
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>
当我按下搜索按钮时,出现以下错误
ERROR TypeError: _r0 is not a function
at UploadPhotoComponent_Template_input_keyup_enter_4_listener (upload-photo.component.html:4)
at executeListenerWithErrorHandling (core.js:14296)
at wrapListenerIn_markDirtyAndPreventDefault (core.js:14331)
at platform-browser.js:582
at platform-browser.js:1278
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Object.onInvoke (core.js:27149)
at ZoneDelegate.invoke (zone-evergreen.js:363)
at Zone.runGuarded (zone-evergreen.js:133)
at NgZone.runGuarded (core.js:27060)
但是,当我将模板引用变量从 #search 更改为 #searchFiled 时,它工作正常
<mat-form-field class="search-field">
<mat-label>Search</mat-label>
<input type="text" (keyup.enter)="search($event)" matInput #searchFiled>
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>
这是什么原因?
解决方案
就我而言,我将登录函数命名为与我的本地模板变量之一相同
<form #login="ngForm">
<input type="email" name="Email" #Email="ngModel" required email [(ngModel)]="email" placeholder="Enter Email">
<br>
<input type="password" name="Password" #Password="ngModel" required [(ngModel)]="password" placeholder="Enter Password">
<br>
<span *ngIf="showMsg">Login Failed !</span>
<button type="button" (click)="login()" [disabled]="login.invalid">LOGIN</button>
</form>
推荐阅读
- docker - Traefik v2 反向代理到 Docker 外部的本地服务器
- postgresql - 如何在sql的where列中使用新创建的列?
- java - 如何从 cloud_run 获取 instanceid?
- javascript - 如何从 createElement 插入图标
- c# - 如何将 JSON 中的数组转换为控制器可以处理的数据类型
- pyspark - 为什么 exp 函数在 pyspark 中不起作用?
- python - 使用 Beautiful soup(
- perl - apache2:Perl lib 版本 (5.28.1) 与可执行文件 '/usr/sbin/apache2' 版本 (5.20.2) 不匹配
- html - CSS 定位在父元素之外
- docxtemplater - Docxtemplater 可变数据键