I'm trying to grab a property from a socket from the server like this
isVerified() {
this.socket.emit('verify');
return new Observable<boolean>(observer => {
this.socket.on('isVerified', data => {
observer.next(data)
observer.complete()
})
})
}
data will either return true or false so in my route guard I have this
canActivate(): Observable<boolean> {
this._chat.isVerified()
.subscribe(
res => {
return res
},
err => console.log(err)
)
}
but it tells me "A function whose declared type is neither 'void' nor 'any' must return a value." and I've been bashing my head trying to figure out to make this work and I've read plenty of other questions to no avail. Console logging res does give me true or false.
canActivate
return type is Observable | Promise | boolean
So you should return an observable in your case:
canActivate(): Observable<boolean> {
this._chat.isVerified();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.