I am new in Angular 2 but I have good experience in Angular 1.x.
I am getting error: Cannot find module 'aspect.js/dist/lib/aspect'
Below are my code:
logging.aspect.ts
import {Injectable} from '@angular/core';
import {beforeMethod, Metadata} from 'aspect.js/dist/lib/aspect';
@Injectable()
export class LogAspect {
@beforeMethod({
classNamePattern: /(Matter|Customer)Service/,
methodNamePattern: /^(get)/
})
invokeBeforeMethod(meta: Metadata) {
console.log(`Inside of the logger.
Called ${meta.className}.${meta.method.name}
with args: ${meta.method.args.join(', ')}.`
);
}
}
aspect defines an advice which is applied to all method calls starting with get within classes containing the regex-pattern (Matter|Customer)Service in their name. The Metadata available to the advice may contain the actual method- and class names along with the method-call parameters
invoice.service.ts
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/Rx';
import {Wove} from 'aspect.js/dist/lib/aspect';
import {Matter} from './Matter.model';
@Injectable()
@Wove()
export class MatterService{
private url: string;
constructor(private http: Http) {
this.url = '/data/matters/data.json';
}
get(): Observable<Matter[]> {
return this.http.get(this.url)
.map(
(response) => <Matter[]>response.json()
);
}
}
And please suggest any other way to implement AOP in angular2