Typescript 财产';parentElement';不存在于类型';EventTarget';
发展就是这项工作 生产模式此错误 如果删除FocusEvent,则会出现相同的错误Typescript 财产';parentElement';不存在于类型';EventTarget';,typescript,angular5,Typescript,Angular5,发展就是这项工作 生产模式此错误 如果删除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 (m
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(事件:FocusEvent){
this.additionSearchMAC=event.srcElement.parentElement.attributes[“ng reflect model”].value;
$(event.srcement).val(this.additionSearchMAC);
}
仅在开发模式下呈现ng reflect model
属性,该属性仅用于调试目的(请参阅)
因此,您不应该尝试在应用程序的代码中访问它们
似乎您正在尝试访问1)当前组件或2)某个父组件的ngModel。
如果为1),只需直接使用模板中引用的变量(例如,([ngModel])=myVar
意味着您可以使用this.myVar
在组件代码中访问它)
如果2)使用@Input()
,将ngModel
向下传递给使用该模型的组件
顺便说一句:在angular中使用jquery的
val()
函数为表单控件设置值很可能是不好的做法(如果可能的话,使用ngModel或FormControl)。这太棒了!