
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
angular2-resource-and-ajax-interceptor
Advanced tools
angular2-resource-and-ajax-interceptor is angular2 http service helper.
angular2-resource and ajax interceptor is service helper class. You can extends and enjoy like angular 1 resource feature
The sources for this package are in (https://github.com/rajan-g/angular2-resource.git) repo. Please file issues and pull requests against that repo. ###Install from npm
npm install angular2-resource-and-ajax-interceptor
import { bootstrap } from '@angular/platform-browser-dynamic';
import { HTTP_PROVIDERS } from '@angular/http';
import {AppComponent} from './app.component';
import {Resource} from './httpresource/resource';
import {AjaxInterceptor} from './httpresource/ajax-interceptor';
import {InterceptorConfig} from './interceptor-config';
bootstrap(AppComponent,[HTTP_PROVIDERS, Resource, AjaxInterceptor,InterceptorConfig])
import {Injectable, Inject} from '@angular/core';
import {Resource} from './httpresource/resource';
import { Http, Headers, Response} from '@angular/http';
import {AjaxInterceptor} from './httpresource/ajax-interceptor';
@Injectable()
export class SampleRestService extends Resource {
// resource:Resource
constructor( @Inject(Http) http: Http, ajaxInterceptor:AjaxInterceptor) {
super(http,ajaxInterceptor);
this.config('/user/:id', {id:'@id'}, {
getList: {
method: 'get'
},
saveMyData:{
params: { id: '@id'},
url: 'customer/:id',
method: 'post',
header: {'contentType': 'application/json', 'custom-key':'sample value'}
}
});
}
};
import {Injectable} from '@angular/core';
import {AjaxInterceptor} from './httpresource/ajax-interceptor';
@Injectable()
export class InterceptorConfig {
constructor() {
}
invoke(ajaxInterceptor: AjaxInterceptor) {
//invoke interceptor
ajaxInterceptor.config(this.onBeforRequest, this.onAfterResponse, this.onAfterResponseError);
}
onBeforRequest(requestCall:any) {
console.log('new header adde');
requestCall.headers.append('Accept', 'application/json');
requestCall.headers.append('Content-Type', 'application/json');
requestCall.headers.append('Authorization', 'Bearer ' + localStorage.getItem('token'));
return requestCall;
}
onAfterResponse(response) {
console.log('response', response);
}
onAfterResponseError(error) {
console.log('error', error);
}
}
import {Component} from '@angular/core';
import {SampleRestService} from './sample-restservice';
import {InterceptorConfig} from './interceptor-config';
import {AjaxInterceptor} from './httpresource/ajax-interceptor';
@Component({
selector: 'my-app',
directives: [],
providers: [SampleRestService],
template: `sample rest service`
})
export class AppComponent {
constructor(private sampleRestService: SampleRestService, private interceptorConfig: InterceptorConfig, ajaxInterceptor:AjaxInterceptor) {
this.sampleRestOperations();
this.interceptorConfig.invoke(ajaxInterceptor);
}
sampleRestOperations() {
//default method
this.sampleRestService['save']({}, { id: 'sampledata' }).then((data) => {
console.log("Data", data);
}, (error) => {
console.log("Data", error);
});
//default method
this.sampleRestService['update']({'id': '12'}, { id: 'sampledata' }).then((data) => {
console.log("Data", data);
}, (error) => {
console.log("Data", error);
});
//default method
this.sampleRestService['get']({}).then((data) => {
console.log("Data", data);
}, (error) => {
console.log("Data", error);
});
//default method
this.sampleRestService['list']({}).then((data) => {
console.log("Data", data);
}, (error) => {
console.log("Data", error);
});
//custome method
this.sampleRestService['saveMyData']({'id': '12'}, { id: 'sampledata' }).then((data) => {
console.log("Data", data);
}, (error) => {
console.log("Data", error);
});
//custome method
this.sampleRestService['getList']({}, { id: 'sampledata' }).then((data) => {
console.log("Data", data);
}, (error) => {
console.log("Data", error);
});
}
}
npm install
npm start
FAQs
angular2-resource-and-ajax-interceptor is angular2 http service helper.
We found that angular2-resource-and-ajax-interceptor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.