using interceptors global block ui angular

Posted: June 2, 2015 in web

app.js


$httpProvider.interceptors.push(['$rootScope', '$q', 'blockUI', function ($rootScope, $q, blockUI) {
var myBlockUI;
return {
request: function (config) {
if(config.blockUI){
myBlockUI = blockUI.instances.get(config.blockUI);
myBlockUI.start();
}
return config;
},
response: function (response) {
if(myBlockUI){
myBlockUI.stop();
}
return response;
}
};

Service


return {
login: function () {
$http.post(url, data, {me: false, blockUI: 'loginBlock'})
.success(function (response) {
...
})
.error(function (response) {
...
});
},

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s