我使用vanilla SDK成功地將 Typeform 嵌入到 Angular 組件中。
但是,當我嘗試從 onSubmit 回呼函式中訪問 Angular 服務時,我收到以下錯誤。
ERROR TypeError: Cannot read properties of undefined (reading '_authService')
這是代碼:
export class OnboardComponent implements AfterViewInit {
@ViewChild('formContainer') formContainer:any;
constructor(private _userService:UserService, private _authService: AuthService) {
}
ngAfterViewInit(): void {
createWidget("<<Form ID>>", {
enableSandbox: true,
container: this.formContainer.nativeElement,
onSubmit: this.formFilled,
});
}
formFilled() {
this._authService.currentUser$.subscribe(user => {
this._userService.setUserOnboarded(user);
});
}
}
關于如何解決這個問題的任何想法?
uj5u.com熱心網友回復:
嘗試使用系結保持背景關系:
ngAfterViewInit(): void {
createWidget("<<Form ID>>", {
enableSandbox: true,
container: this.formContainer.nativeElement,
onSubmit: this.formFilled.bind(this),
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/433928.html
上一篇:RxJS計時器不等待指定時間?
