I am fairly new to Angular and am working on incorporating an existing jQuery AJAX API into Angular.
Right now I am doing stuff like:
$.myApi.login('username', 'password').done(function(result) {
//do stuff
$scope.$apply(); //apply changes to Angular app
}).fail(function(result) {
//do stuff if login failed
$scope.$apply(); //apply changes to Angular app
});
Is there a cleaner way to integrate APIs like this than just writing $scope.$apply()
everywhere? Can I integrate with Angular's $http
somehow without ditching the existing functions and just making raw AJAX requests to the URLs (i.e. can I reuse the existing API's functions directly)?
$myApi.login()
and instead just call the URL that$myApi.login()
would have called, instead using$http.post('/loginUrl/')
etc.? Is that pretty much the cleanest way to do it? Or can I reuse the jQuery functions somehow? – Nick Tiberi 17 hours ago$scope.$apply()
. That is what i could think about, there might be another alternative but these are the only ones that comes to my mind. – PSL 17 hours ago