我有一个搜索字段,当按下回车键时会触发搜索方法。
<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>
Run Code Online (Sandbox Code Playgroud)
当我按下搜索按钮时出现以下错误
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)
Run Code Online (Sandbox Code Playgroud)
但是,当我将模板引用变量从 #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>
Run Code Online (Sandbox Code Playgroud)
这是什么原因呢?
检查你的html。您可能有这样的标签:
<ng-template #searchFiled>
Run Code Online (Sandbox Code Playgroud)
如果替换#searchFiled为#search,则必须将其更改为ng-templatetoo。
| 归档时间: |
|
| 查看次数: |
2189 次 |
| 最近记录: |