从另一个类调用函数发出Angular

时间:2018-05-16 11:43:32

标签: angular angular-ui-router this store angular-directive

在另一页上调用函数时;它的参数“this”与前一页的参数“this”相同。

从CheckAuthorizationOnClickDirective页面调用的函数;

  export class CheckAuthorizationOnClickDirective {
            user: Observable<User>;
            @Input() allowedClaim: any;
            @Input() checkAuthOnClick = () => { };
            observer: MutationObserver;

            constructor(private element: ElementRef,
                private store: Store<fromRoot.State>) {
                this.element = element.nativeElement;
            }

            @HostListener('click', ['$event, $event.target'])
            onClick(event, targetElement) {       
                if (!this.checkAuth()) {
                    this.checkAuthOnClick()   //calling loadForm function
                }
            }
           ...

InvoiceDesignListPage中的功能;

 loadForm() {
        this.router.navigate(['/ayarlar/fatura-gorsel/duzenle', this.selectedInvoiceDesign.Id]);
      }

但是“this”键值是CheckAuthorizationOnClickDirective,因此会出现异常。

0 个答案:

没有答案