Inspiration for Custom Decorators in Angular
Netanel Basal
3747

Hi Netanel

Thanks for great post, I have a little problem, question..
Could you tell me why decorated method have access to class methods via this, but does NOT have properties in this object?

Could you try that you can access this.posts$ in your decorated method scroll()?

My case:
timeouted.decorator.ts

export function timeouted( miliseconds: number = 500 ): MethodDecorator {

return function ( target : any, propertyKey : string, descriptor : PropertyDescriptor ) {

const original = descriptor.value

descriptor.value = function () {
// console.log( `Calling "${propertyKey}" with`, arguments )
let args = arguments;
return setTimeout( () => original.apply( target, args ), miliseconds )
}

return descriptor
}

}

mypage.module.ts

...
import { timeouted } from 'timeouted.decorator';
...
constructor
(
public navCtrl: NavController,
public navParams: NavParams,
) {
// this.navCtrl = navCtrl // tried this.. did not work
}

@timeouted(350)
goToIdCardScanFrontPage() {
this.navCtrl.push(IdCardScanFrontPage);
}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.