aman
aman

Reputation: 75

$state.go not working properly. It works only first time, but not second time

   vm.add=funtion(data) {
    causeService.add(data)
     .then(function(response){
      if(response.status = 'success'){
       $state.go('student.list');
        } else {
           //  
        }
   });
   }

I'm trying to add user. When this function is called first time it works. When this function is called the second time it does not go to state. There is no error.

Upvotes: 0

Views: 540

Answers (1)

Peter LaBanca
Peter LaBanca

Reputation: 485

Make sure that your promise is properly resolving in your causeService.add() method. If it does not resolve properly, the then method will never get called.

Also, your conditional only includes a single equals sign, which will always return true because it will return the value of response.status which you are setting to 'success'. See below:

if(response.status === 'success'){
    $state.go('student.list');
} else {
    // Do something if not successful
}

Upvotes: 2

Related Questions