Aditya Krishna Namdeo Aditya Krishna Namdeo - 5 months ago 21
AngularJS Question

using $location.path() for redirection in firebase

I want to redirect to different page after successful submission of form in angularjs using firebase.
I am using push() for pushing data in database of firebase.Here is my controller implementation-

.controller('AddPostCtrl',['$scope','$location',function($scope,$location){


$scope.AddPost=function(event){
var firebaseObj=new Firebase("https://boiling-inferno-5476.firebaseio.com/Article");
event.preventDefault();
var title=$scope.article.title;
var post=$scope.article.post;
firebaseObj.push({
title:title,
post:post
},function(error){
if(error)
{
console.log(error);
}
else
{
$location.path('/welcome');
}
})

}
}])


On clicking submit button of form page should be redirected to 'welcome' page,but i have to click twice to do that.is there any error in my implementation.

Answer

Try this:

$scope.$apply(function() {
    $location.path('/welcome');
});
Comments