Reputation: 77
Development mede this work!!
Production mode this error!!
If you remove FocusEvent, the same error.
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);
}
Upvotes: 0
Views: 1129
Reputation: 310
The ng-reflect-model
attribute is only rendered in development mode and it is only there for debugging purposes (see What does the "ng-reflect-*" attribute do in Angular2/4? )
So you shouldn't try to access them in your application's code.
It appears you're trying to access the ngModel of either 1) the current component or 2) some parent component.
If 1), just directly use the variable you referenced in your template (e.g. ([ngModel])=myVar
means you can use this.myVar
to access it in the component code)
If 2) Pass the ngModel
downwards to the component yourusing this in with an @Input()
.
Btw.: Setting a value to a form control using jquery's val()
function in angular is most likely bad practice (If possible, use ngModel or a FormControl instead).
Upvotes: 1