Type error :- can't read properties of undefined (reading get)

Priya75
Tera Contributor

 

c.hostname = function() {
    var host;
    
    $timeout(function() {
        host = c.hostname; 
        this.server.get({
            action: 'getvaluefromserver', 
            name: host /
        }).then(function(response) {
            c.cloudedata = response.data.cloudpro;
            console.log("data: " + response.data.cloudpro);
        });
    }, 5000); // 5000 milliseconds = 5 seconds
}

 

this is my code , I am getting this error in console at the portal

4 REPLIES 4

Sohithanjan G
Kilo Sage
Kilo Sage

Hi @Priya75 

 

Can you try with this

c.hostname = function() {
    var host;

    $timeout(function() {
        host = c.hostname; // This line might be incorrect, it seems you want to assign a value to 'host' from some source
        if (this.server) {
            this.server.get({
                action: 'getvaluefromserver', 
                name: host
            }).then(function(response) {
                c.cloudedata = response.data.cloudpro;
                console.log("data: " + response.data.cloudpro);
            });
        } else {
            console.error("this.server is not defined");
        }
    }, 5000); // 5000 milliseconds = 5 seconds
}

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

c.hostname i am getting from HTML , after using your code , i am getting error as "this.server is not defined.";

add var c = this; at the top


 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

it is already added to the code. still getting the same error "this.server" is not defined. when checked  this.server in console it is coming as undefined.