简体   繁体   中英

I got this error ,can someone tell me how to fix this

core.js:4442 ERROR TypeError: Cannot read property 'name' of null

    setTimeout(() => {
        this.userDetails = this.cacheService.getUser();
            this.userName = this.userDetails.name;
          }, 1000);

it means that the object "userDetails" is equal to null so you can't get the property "name" out of it, you must first make sure "userDetails" was assigned a value like:

this.userDetails.name= "Jhon Doe"

Try to set your script at the bottom of your.HTML page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM