2017-05-04 82 views
-3

我得到这个错误,当我编译角2错误TS1005:“”预计

我不觉得,我应该添加逗号。

src/app/navbar.component.ts(29,39): error TS1005: ',' expected. 
src/app/tache.service.ts(53,53): error TS1005: ',' expected. 

navbar.component.ts

 add(name: string): void { 
     name = name.trim(); 
     if (!name) { return; } 
     this.tacheService.create(name) 
     .then(tache => { 
      this.tacheService.insert(tache: Tache); // the first error (line 29) 
     }); 
     } 

service.ts

update(tache: Tache): Promise<Tache> { 
     tache.stat = 1; 
     return this.http 
      .put(this.tachesUrl, JSON.stringify(tache.stat:1), {headers: this.headers}) // second error (line 53) 
      .toPromise() 
      .then(() => tache) 
      .catch(this.handleError); 
     } 
+1

'JSON.stringify(tache.stat:1)'是无效的语法 –

回答

4

我不认为你可以用参数传递数据类型:

this.tacheService.insert(tache: Tache); 

应该是

this.tacheService.insert(tache); 
+0

事实上。 'JSON.stringify(tache.stat:1)'也是无效的语法。 –

+1

确实,你在*参数*(和变量和...)上注释类型,而不是*参数*。 –

0
this.tacheService.insert(tache: Tache); // the first error (line 29) 
this.tacheService.insert(tache); // No Error 

return this.http 
    .put(this.tachesUrl, JSON.stringify(tache.stat:1), { 
     headers: this.headers 
    }) // second error (line 53) 
    .toPromise() 
    .then(() => tache) 
    .catch(this.handleError); 

return this.http 
    .put(this.tachesUrl, JSON.stringify(tache.stat), { 
     headers: this.headers 
    }) // No Error 
    .toPromise() 
    .then(() => tache) 
    .catch(this.handleError);