我正在开始学习Angular2,遵循他们在页面上提供的
quickstart,现在我试图做一些
Http requests.但每当我启动组件时,Chrome会不断给我这个错误:
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
这是组件:
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); }); } }
和引导:
import {bootstrap} from 'angular2/platform/browser' import {UsersComponent} from './components/users' bootstrap(UsersComponent,[HTTP_PROVIDERS]);
只有{{people}}的观点.
TypeScript正在编译OK.我甚至不知道是什么失败!