2017-05-04 77 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);