Angular2 Http错误
发布时间:2020-12-17 07:42:09 所属栏目:安全 来源:网络整理
导读:我正在开始学习Angular2,遵循他们在页面上提供的 quickstart,现在我试图做一些 Http requests.但每当我启动组件时,Chrome会不断给我这个错误: Uncaught SyntaxError: Unexpected token http:1Uncaught SyntaxError: Unexpected token angular2-polyfills.js
我正在开始学习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.我甚至不知道是什么失败!
文件缺乏这方面.路由器和Http需要添加到index.html.容易犯错误
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |