Parameter Decorators

  1. function logPosition(target: any, propertyKey: string, parameterIndex: number) {
  2. console.log(parameterIndex);
  3. }
  4. class Cow {
  5. say(b: string, @logPosition c: boolean) {
  6. console.log(b);
  7. }
  8. }
  9. new Cow().say('hello', false); // outputs 1 (newline) hello

The above demonstrates decorating method parameters. Readers familiar withAngular can now imagine how Angular implemented their@Inject() system.

原文: https://angular-2-training-book.rangle.io/handout/features/parameter_decorators.html