srujana
srujana

Reputation: 453

How to execute a function for a particular time period in angularjs?

I am working in angularjs and ionic project. Here I need to change the state and after 10 seconds, I need to come back to the previous state.
Below is my code:

if (response.data[i].id == opport.id && response.data[i].status == 2 && response.data[i].contractor_fse_counterprice == "accept") {
    $state.go("tab.chats");
    /*setTimeout(function () {
        $state.go("tab.chats")
    }, 10000);*/
}

How can I implement the time interval for execution of the function of changing state and returning back after 10 seconds in angularjs?

Upvotes: 0

Views: 83

Answers (1)

Chukwuemeka Onyenezido
Chukwuemeka Onyenezido

Reputation: 349

AngularJs has a $timeout function.

Simply inject $timeout in your controller and then use it in the format below;

$timeout(function()  {
  // what to call
$state.go("tab.chats")
}, 10000) // 10000 = 10 seconds

Upvotes: 1

Related Questions