Type error :- can't read properties of undefined (reading get)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 03:32 AM - edited 03-06-2024 03:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 06:54 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 08:17 PM - edited 03-06-2024 08:25 PM
c.hostname i am getting from HTML , after using your code , i am getting error as "this.server is not defined.";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 07:40 AM
add var c = this; at the top
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 09:40 PM - edited 03-08-2024 12:04 AM
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.