$location.path not working when using third party library with AngularJS
I am building an application using AngularJS where all the API call to the
web service is carrying out by a third party JavaScript file.
Here is my controller code;
app.controller('LoginCtrl', function ($scope, $location,FlashService,
$http) {
var MyAPI = new MyAppAPI("http://localhost/myapp");
$scope.logout = function () {
var data = FluentXS.logout();
if(data) {
localStorage.removeItem('session_id');
$location.path('/login').replace();
$scope.$apply()
FlashService.show(data.statusMessage);
}
};
});
Here is my JavaScript file from which API call is making;
function FluentXSApi (url) {
this.baseUrl =url
this.serviceData = function(method,path, async, body, callback){
if(method=='GET')
{
return jQuery.ajax({
url: path,
async: async,
dataType:'json',
success: function(data){callback(data)},
error: function(e){console.log(e)}
});
}
else if(method=='POST')
{
return $.ajax({
url: path,
type : 'POST',
async: async,
contentType : 'application/json',
data: JSON.stringify(body),
dataType: 'json',
success: function(data){callback(data)},
error: function(e){console.log(e)}
});
}
};
this.logout = function() {
var dataTemplates;
var httpMethod='GET';
var path =
this.baseUrl+"/api/user/logout.{format}".replace(/{format}/g,'json');
//alert(path);
this.serviceData(httpMethod,path, false, null, function (data) {
dataTemplates = data;
return dataTemplates;
}
When I am trying this $location.path is not at all working and console is
throwing an error $apply already in progress. What am I doing wrong here?.
No comments:
Post a Comment