【发布时间】:2018-08-09 13:37:43
【问题描述】:
尝试了来自不同站点的几种解决方案,但没有帮助。 问题是:尝试运行我的应用程序但出现以下错误:
10% 构建模块 0/1 模块 1 处于活动状态…\src\app\contacts\contacts.component.tsERROR in src/app/contact.service.ts(18,7): error TS1128: Declaration or statement expected. src/app/contact.service.ts(27,7):错误 TS1128:需要声明或声明。 src/app/contact.service.ts(33,7):错误 TS1128:需要声明或声明。
import { Injectable } from '@angular/core';
import { Http, Headers, Response} from '@angular/http';
import { Contact } from './contact';
import 'rxjs/add/operator/map';
import { map } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class ContactService {
constructor(private http: Http) { }
// Retrieving contacts
getContacts() {
return this.http.get('http://localhost:3000/api/contacts');
.map((res: any) => res.json());
}
// Adding contacts
addContact(newContact) {
var headers = new Headers;
headers.append('Content-Type', 'application/json');
return this.http.post('http://localhost:3000/api/contact', newContact, {headers: headers});
.map((res: Response) => res.json());
}
// Delete contact method
deleteContact(id) {
return this.http.delete('http://localhost:3000/api/contact' + id);
.map((res: Response) => res.json());
}
}
.map((res: any) => res.json()); 行说:
需要声明或声明。
【问题讨论】:
-
为什么
;在.map之前?应该是return this.http.get('http://localhost:3000/api/contacts').map((res: any) => res.json()); -
我认为
.map()应该是.then()(?) -
@Titian Cernicova-Dragomir : 删除 ';'解决了我的问题。谢谢。
标签: angularjs typescript