添加对象而不删除存储在变量上的旧数据

时间:2017-08-21 13:48:48

标签: angular typescript

我需要将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[]'.

是否可以在变量线程中添加数据?

0 个答案:

没有答案