I recently started using Angular 2, although I have a strong background in Angular 1.x.
An error message is appearing: Cannot find module 'aspect.js/dist/lib/aspect'
Here is the code snippet causing the issue:
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(', ')}.`
);
}
}
The aspect in this code defines advice that applies to method calls starting with get within classes containing either MatterService or CustomerService in their names. The metadata available to the advice includes the 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()
);
}
}
Please provide suggestions for alternative ways to implement AOP in Angular 2.