我需要将Thread
个对象添加到我的变量threads
中。这是我的功能:
newThreads: Thread[];
newThreadsId : string[];
threads: Observable<{ [key: string]: Thread }>;
addThread(keyThread: string, newThread: Thread): void {
this.threadService.newThreads.push(newThread);
this.threadService.newThreadsId.push(newThreadId);
let result = {[this.threadService.newThreadsId]: this.threadService.newThreads};
this.threadService.threads = Observable.of(result);
this.threadService.threads = Observable.of(result);
}
我有这个错误:
A computed property name must be of type 'string', 'number', 'symbol', or 'any
Type 'Observable<{ [x: string]: Thread[]; }>' is not assignable to type 'Observable<{ [key: string]: Thread; }>'. Type '{ [x: string]: Thread[]; }' is not assignable to type '{ [key: string]: Thread; }'. Index signatures are incompatible. Type 'Thread[]' is not assignable to type 'Thread'. Property 'id' is missing in type 'Thread[]'.
是否可以在变量线程中添加数据?