当我尝试创建新任务时,浏览器控制台中出现这样的错误,请告诉我如何解决。
ERROR Error: Uncaught (in promise): TypeError: _this.tasks.unshift is not a function
TypeError: _this.tasks.unshift is not a function
at form.ts:62
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:3757)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)
at zone.js:872
form.ts
59 createTask() {
60 this._taskService.create(this.createTaskForm.value)
61 .then(data => {
62 this.tasks.unshift(data);
63 this._taskService.tasks.next(this.tasks);
64 this.resetForm();
65 });
66 }
task.ts
40 create(task): Promise<any | Task> {
41 task['due_date'] = task['due_date']['formatted'];
42 let body = JSON.stringify({task: task});
43 const url = `${this.tasksUrl}?access_token=${localStorage.getItem('token')}`;
44 return this.http.post(url, body, { headers: this.headers })
45 .toPromise()
46 .then(res => res.json() as Task)
47 .catch(error => {
48 this.handleError(error, 'Could not create task!')
49 });
50 }