我是新的角度和打字,尝试学习它 this tutorial . 教程中有一个处理程序如下所示:
removeChat(chat: Chat): void { this.chats = this.chats.map<Chat[]>(chatsArray => { const chatIndex = chatsArray.indexOf(chat); chatsArray.splice(chatIndex, 1); return chatsArray; }); }
of 和 map 是可观察的方法,当情况不再是这样的时候。所以我试着通过分别导入它们来修复它。 属于 地图 可能是因为我对语法理解不够好(我非常精通Javascript,但typescript对我来说还是很新的)。所以我试过这样的方法
of
map
属于
地图
import { map } from 'rxjs/operators'; // later... removeChat(chat: Chat): void { this.chats = map<Chat[], {}>(chatsArray => { const chatIndex = chatsArray.indexOf(chat); chatsArray.splice(chatIndex, 1); return chatsArray; }); }
但我得到了一个错误:
“可观察的”。类型中缺少属性“\u isScalar”
我做错什么了?
目前,还不知道是哪个 Observable 它应该在操作。相反,您应该将它与 pipe
Observable
pipe
removeChat(chat: Chat): void { this.chats = this.chats.pipe( map(chatsArray => { const chatIndex = chatsArray.indexOf(chat); chatsArray.splice(chatIndex, 1); return chatsArray; })); }