gpt4 book ai didi

Angular2 [typescript] 注入(inject) Http 到服务时出错

转载 作者:行者123 更新时间:2023-12-02 09:29:38 26 4
gpt4 key购买 nike

有问题的来源:https://github.com/clicman/angular2-app/

我尝试将 Http 注入(inject)服务,但出现错误:

http:1 Uncaught SyntaxError: Unexpected token <__exec @ system.src.js:1374entry.execute @
system.src.js:3300linkDynamicModule @ system.src.js:2921link @ system.src.js:2764execute @
system.src.js:3096doDynamicExecute @ system.src.js:715link @ system.src.js:908doLink @
system.src.js:569updateLinkSetOnLoad @ system.src.js:617(anonymous function) @ system.src.js:430run @
angular2-polyfills.js:138zoneBoundFn @ angular2-polyfills.js:111lib$es6$promise$$internal$$tryCatch @
angular2-polyfills.js:1511lib$es6$promise$$internal$$invokeCallback @
angular2-polyfills.js:1523lib$es6$promise$$internal$$publish @ angular2-polyfills.js:1494(anonymous
function) @ angular2-polyfills.js:243run @ angular2-polyfills.js:138zoneBoundFn @
angular2-polyfills.js:111lib$es6$promise$asap$$flush @ angular2-polyfills.js:1305
angular2-polyfills.js:138 Uncaught SyntaxError: Unexpected token <
Evaluating http://localhost:3000/angular2/src/http/http
Error loading http://localhost:3000/scripts/boot.js

服务代码:

import {Injectable} from 'angular2/core'
import {Http} from 'angular2/src/http/http';
@Injectable()
export class CommentsService {
constructor(private _http: Http) { }
public getComments(): any[] {
return [];
}
}

我做错了什么?

最佳答案

您应该将 angular2/bundles/http.dev.js 添加到 index.html

关于Angular2 [typescript] 注入(inject) Http 到服务时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34452080/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com