I tried code follow:
@Component({
selector: 'test-content',
template: '
<div *ngIf="sv.name.notExist.testUndefined != undefined">
{{sv.name.notExist.testUndefined}}
',
directives: [FORM_DIRECTIVES]
})
The variable sv.name.notExist.testUndefined is undefined, but i check it with *ngIf and the result is error with message: "TypeError: Cannot read property 'testUndefined' of undefined in [sv.name.notExist.testUndefined != undefined in ..."
Please help me check variable undefined with *ngIf.
To solve the "Cannot read properties of undefined" error, make sure that the DOM element you are accessing exists. The error is often thrown when trying to access a property at a non-existent index after using the getElementsByClassName() method.
The "Cannot read property 'props' of undefined" error occurs when a class method is called without having the correct context bound to the this keyword. To solve the error, define the class method as an arrow function or use the bind method in the classes' constructor method.
To solve the "Cannot read property 'value' of null" error, make sure you aren't accessing the value property on a null value, e.g. a non-existent DOM element. An element with the provided id does not exist in the DOM, so the getElementById method returns null .
The TypeError: Cannot read property of undefined is one of the most common type errors in JavaScript. It occurs when a property is read or a function is called on an undefined variable. Install the JavaScript SDK to identify and fix these undefined errors.
I think that you should use the elvis operator
<div *ngIf="sv?.name?.notExist?.testUndefined">
This link could give you more details: https://angular.io/docs/ts/latest/guide/template-syntax.html. See the section "The Elvis Operator ( ?. ) and null property paths".
Hope it helps you, Thierry
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With