Tôi bắt đầu học Angular2 bằng cách theo dõi quickstart chúng cung cấp trong trang của họ và giờ tôi đang cố gắng thực hiện một số Http requests. Nhưng bất cứ khi nào tôi bootstrap thành phần, Chrome tiếp tục đem lại cho tôi lỗi này:Lỗi Angular2 Http
Uncaught SyntaxError: Unexpected token < http:1
Uncaught SyntaxError: Unexpected token < angular2-polyfills.js:138
Evaluating http://localhost:3000/angular2/http
Error loading http://localhost:3000/app/boot.js
Đây là thành phần:
import {Component} from 'angular2/core';
import {HTTP_PROVIDERS, Http} from 'angular2/http';
@Component({
selector: 'users',
providers: [HTTP_PROVIDERS],
templateUrl: 'app/views/users.html'
})
export class UsersComponent {
people: Object[];
constructor(http: Http) {
http.get('http://192.168.56.101/api/test').subscribe(res => {
this.people = res.json();
console.log(this.people);
});
}
}
Và bootstrapping:
import {bootstrap} from 'angular2/platform/browser'
import {UsersComponent} from './components/users'
bootstrap(UsersComponent, [HTTP_PROVIDERS]);
Quan điểm chỉ {{people}}
là.
TypeScript đang biên dịch OK. Tôi thậm chí không biết những gì đang thất bại!
Xem http://stackoverflow.com/a/34402203/4933038 –