【发布时间】:2019-12-18 10:19:45
【问题描述】:
调用函数时没有任何问题,但是在 setInterval 中调用它时,所以每秒继续调用它给我一个错误:无法读取服务上未定义的属性!
constructor(private route: ActivatedRoute,private
conversationService:ConversationService) {
}
ngOnInit() {
this.sender = this.route.snapshot.paramMap.get("username");
this.receiver = sessionStorage.getItem("username");
setInterval(
function()
{
this.conversationService.
getTheConversation(this.receiver,this.sender).subscribe(
data=>this.result=data)
},1000);
}
错误: 错误类型错误:无法读取未定义的属性“getTheConversation”
【问题讨论】:
-
为什么不使用 rxjs 定时器?有些像
timer(0,1000).pipe(switchMap(()=>{return this.conversationService.getTheConversation(this.receiver,this.sender)})).subscribe(data=>this.result=data)
标签: javascript angular typescript ecmascript-6