我是一名新手在Angular 2中,但我对Angular 1.x有很好的经验。
我遇到了以下错误:
无法找到模块'aspect.js/dist/lib/aspect'
以下是我的代码:
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 定义了一个建议,该建议应用于所有以 get 开头的方法调用,这些方法调用在其名称中含有 regex 模式 (Matter|Customer)Service 的类中。该建议可用于元数据,其中包含实际方法名称和类名称以及方法调用参数。
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()
);
}
}
请提供在Angular2中实现AOP的其他方法。