typescript - “EventTarget”类型上不存在属性“parentElement”
问题描述
开发完成这项工作!!
生产模式这个错误!!
如果删除 FocusEvent,同样的错误。
Cannot read property 'value' of undefined
at e.preSaveMac (main.bundle.js:1)
at Object.handleEvent (main.bundle.js:1)
at Object.handleEvent (main.bundle.js:1)
at Object.handleEvent (main.bundle.js:1)
at Ji (main.bundle.js:1)
at main.bundle.js:1
at t.r [as _next] (main.bundle.js:1)
at t.__tryOrUnsub (main.bundle.js:1)
at t.next (main.bundle.js:1)
at t._next (main.bundle.js:1)
preSaveMac(event:FocusEvent){
this.additionSearchMAC = event.srcElement.parentElement.attributes["ng-reflect-model"].value;
$(event.srcElement).val(this.additionSearchMAC);
}
解决方案
该ng-reflect-model
属性仅在开发模式下呈现,并且仅用于调试目的(请参阅“ng-reflect-*”属性在 Angular2/4 中做了什么?)
所以你不应该尝试在你的应用程序代码中访问它们。
看来您正在尝试访问 1)当前组件或 2)某个父组件的 ngModel。如果 1),只需直接使用您在模板中引用的变量(例如,([ngModel])=myVar
意味着您可以this.myVar
在组件代码中使用它来访问它)如果 2) 将ngModel
向下传递给您使用 this 的组件@Input()
。
顺便说一句:使用 Angular 中的 jquery 函数为表单控件设置值val()
很可能是不好的做法(如果可能,请改用 ngModel 或 FormControl)。
推荐阅读
- python-3.x - 标准缩放器 v 最小最大。Standardscaler 不适用于 ANN,但 MInMax 可以
- java - 如何在 LWJGL 3 中使用 glfwSetWindowUserPointer?
- javascript - 为什么 append() 添加标记多次而不是一次?
- postgresql - 除了删除数据库集群之外,还保留一个静态的大型 Postgres 数据库吗?
- svg - SVG | 擦除另一条路径的一部分
- c# - Linq to Entities:其中包含 1 个值和许多列
- javascript - MiniCssExtractPlugin 没有创建 css 文件
- http - 控制台上的响应与网络上的预览不同
- google-cloud-platform - 在 BigQuery 中使用 MAX 值展平结果
- html - 是否可以仅使用 CSS 来阻止单词换行?