Angular2 HTTP: Uncaught SyntaxError: Unexpected token < polyfills

Angular2 HTTP: Uncaught SyntaxError: Unexpected token < polyfills

所以我正在练习 http post 并从 YouTube 教程中获取 Angular2 的方法,但我无法找出问题所在 这是我的 index.html 个文件:

<html>
<head>
    <title>MyTodo App</title>

<script src="node_modules/es6-shim/es6-shim.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>   
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>

</head>
<body>

    <script>
    System.config({
        packages: {
            app: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
System.import('app.js')
  .then(null, console.error.bind(console));
</script>
    <http-comp>Loading..</http-comp>
</body>
</html>

这是 http 服务文件:

import { Injectable } from 'angular2/core';
import { Http } from 'angular2/http';
import 'rxjs/add/operator/map' ;

@Injectable()
export class webhttpservice{

constructor(private http : Http){}

getfunctionfromapp(){
   return this.http.get('www.google.com')
              .map(res => res.json());
}
}

这里是 app.ts 文件:

import { Component } from 'angular2/core';
import { bootstrap } from 'angular2/platform/browser';
import { webhttpservice } from './httpService';
import { HTTP_PROVIDERS } from 'angular2/http';

@Component({
selector : 'http-comp',
template : `

<button (click) = 'reqfunction()'>Get Request</button>
<p></p>
<br>
<button>Post Request</button>
<p></p>

`,
providers : [webhttpservice]
})
export class httpcomponent{

getdata;
constructor(private var1: webhttpservice){}
reqfunction(){
    this.var1.getfunctionfromapp()
            .subscribe(
                data => this.getdata = JSON.stringify(data),
                error => alert(error),
                () => console.log('Finished')

            );
}

}

bootstrap(httpcomponent, [HTTP_PROVIDERS]);

这些是我得到的原始错误

>Uncaught (in promise) TypeError: object is not a constructor(…)  
httpService:1 Uncaught SyntaxError: Unexpected token <__exec @ 
angular2-polyfills.js:138   
Uncaught SyntaxError: Unexpected token <
Evaluating http://localhost:3000/httpService
Error loading http://localhost:3000/app.jsrun
@ angular2-polyfills.js:138zoneBoundFn @ angular2-

加载包含您的 webhttpservice class TypeScript 文件的请求有点奇怪:

Evaluating http://localhost:3000/httpService

它应该是:http://localhost:3000/app/httpService.js 你的配置...

你把httpService.ts文件放在app文件夹下了吗?根据您的 SystemJS 配置,您应该。