小编Mig*_*l S的帖子

Angular2 Http错误

我开始通过他们在页面中提供的快速入门来学习Angular2 ,现在我正在尝试发出一些Http请求.但每当我引导组件时,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
Run Code Online (Sandbox Code Playgroud)

这是组件:

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);
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

和引导:

import {bootstrap}    from 'angular2/platform/browser'
import {UsersComponent} from './components/users'

bootstrap(UsersComponent, [HTTP_PROVIDERS]);
Run Code Online (Sandbox Code Playgroud)

视图是唯一的{{people}}.

TypeScript正在编译好.我甚至不知道什么失败了!

angular

14
推荐指数
2
解决办法
3454
查看次数

标签 统计

angular ×1