我正在尝试在
我一直在思考使用await函数吗?但我无法弄清楚,请给予任何建议?
这是我的
ngOnInit()
中调用一个函数,并向其提供两个值。所以这是我试图在ngOnInit
内部调用的函数:
this.complexWordIdentification(this.postIWant, this.theHardWords);
问题在于,如您下面所看到的,this.postIWant
和this.theHardWords
在ngOnInit
中被解析,导致错误。那么,如何调用this.complexWordIdentification(this.postIWant, this.theHardWords);
并向它提供这些值而不出错呢?我一直在思考使用await函数吗?但我无法弄清楚,请给予任何建议?
这是我的
ngOnInit
:ngOnInit() {
this.isLoading = true;
this.wordsLoaded = false;
this.postLoaded = false;
this.form = new FormGroup({
annotation: new FormControl(null, {
validators: [
Validators.required,
Validators.minLength(8),
Validators.maxLength(250)
]
})
});
this.id = this.route.snapshot.paramMap.get('postId');
this.annotationService.getWords();
this.annotationSub = this.annotationService
.getWordUpdateListener()
.subscribe((thewords: ComplexWord[]) => {
this.thewords = thewords;
this.thewords.map(word => {
this.theHardWords.push(word.word);
this.wordWithAnnotation.push(word);
});
this.wordsLoaded = true;
this.isLoading = this.postLoaded && this.wordsLoaded;
});
this.postsService.getPosts();
this.postsSub = this.postsService
.getPostUpdateListener()
.subscribe((posts: Post[]) => {
this.posts = posts;
this.posts.map(post => {
if (post.id === this.id) {
this.postIWant = post.fileText;
}
});
this.postLoaded = true;
this.isLoading = !(this.postLoaded && this.wordsLoaded);
});
this.role = this.authService.getUserRole();
this.userIsAuthenticated = this.authService.getIsAuth();
this.authStatus = this.authService
.getAuthStatus()
.subscribe(isAuthenticated => {
this.userIsAuthenticated = isAuthenticated;
this.role = this.authService.getUserRole();
});
}
如果有人能指导我方向,那就太好了,因为我在这个领域并不是很有经验。目前,我必须在ngOnInit
之外调用this.complexWordIdentification(this.postIWant, this.theHardWords);
来避免错误,但显然,我希望自动调用它。