How to use $timeout function to send data to server side on portal

Priya75
Tera Contributor

Hi All, 

 

I am trying to send from the client controller to the server side, I am getting the data on change of field which is a  choice list on portal which is a HTML Field.

 

So i tried without $timeout the data is not coming properly so i am using $timeout. i have used console to check if value is correct on client side. I am getting error as  "cann't read properties of undefined reading get "

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
    }

 

4 REPLIES 4

Riyan17
Kilo Contributor

Utilize the $timeout function in AngularJS to delay sending data to the server-side on a portal. This allows for asynchronous processing, ensuring smooth user experience by avoiding blocking operations while transmitting data to the server.

Priya75
Tera Contributor

how do i send values from client controller to server side by using $timeout, as i am getting error "can't read properties of undefined reading get "

Sohithanjan G
Kilo Sage

Hi @Priya75 


It seems like there are a couple of syntax errors and potential issues in your code snippet. Let's correct them:

 

c.hostname = function() {
    var host;
    // Assuming '$timeout' is injected properly into the controller
    $timeout(function() {
        host = c.hostname; // This line seems incorrect, it's trying to assign 'c.hostname' to 'host' which seems unnecessary
        this.server.get({
            action: 'getvaluefromserver', // Remove the semicolon here
            name: host // Remove the semicolon here and use a comma instead of a semicolon to separate key-value pairs
        }).then(function(response) {
            c.cloudedata = response.data.cloudpro;
            console.log("data: " + response.data.cloudpro);
        });
    }, 5000); // 5000 milliseconds = 5 seconds
}

 

 Please mark as Accepted Solution & HIT helpful if it suffices.. 

still getting the same error "can't read properties of undefined reading get".