加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

typescript – Angular 2 HTTP“无法解析”AppService“的所有参

发布时间:2020-12-17 07:47:24 所属栏目:安全 来源:网络整理
导读:我尝试将http提供程序导入服务,但是我收到以下错误: Cannot resolve all parameters for ‘AppService'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that ‘AppService’ is decorated with Inje
我尝试将http提供程序导入服务,但是我收到以下错误:

Cannot resolve all parameters for ‘AppService'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that ‘AppService’ is decorated with Injectable.

以下是一些代码段:

<script src="~/es6-shim/es6-shim.min.js"></script>
<script src="~/systemjs/dist/system-polyfills.js"></script>

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

<!-- 2. Configure SystemJS -->
<script>
    System.config({
        map: { 'rxjs': 'RCO/rxjs' },packages: {
            RCO: {
                format: 'register',defaultExtension: 'js'
            },'rxjs': {defaultExtension: 'js'}
        }
    });
  System.import('RCO/Areas/ViewOrganization/AngularTemplates/boot')
      .then(null,console.error.bind(console));

boot.ts

import {bootstrap} from 'angular2/platform/browser'
import {HTTP_PROVIDERS} from 'angular2/http'
import 'rxjs/add/operator/map'
import {AppComponent} from  'RCO/Areas/ViewOrganization/AngularTemplates/app.component'
import {AppService} from 'RCO/Areas/ViewOrganization/AngularTemplates/app.service'

bootstrap(AppComponent,[HTTP_PROVIDERS,AppService]);

app.service.ts

import {Injectable} from 'angular2/core';
import {Http,Response} from 'angular2/http';
import {Observable} from 'rxjs/Rx';

@Injectable()
export class AppService {

    constructor(private http: Http) { }

    // Uses http.get() to load a single JSON file
    getTableData() {
        return this.http.get('...').map((res: Response) => res.json());
    }

}

我试图在服务器上调用控制器,最终将JSON文件加载到数据表中.很简单的东西,但是我加载Http模块的方式似乎是错误的.任何帮助将不胜感激.

似乎就像您没有使用typescript编译器来将文件传递给js,在这种情况下,您需要在注入组件构造函数内的任何依赖项时使用@Inject.
import {Injectable,Inject} from 'angular2/core';
import {Http,Response} from 'angular2/http';
import {Observable} from 'rxjs/Rx';

@Injectable()
export class AppService {
    constructor(@Inject(Http) private http: Http) { }
    // Uses http.get() to load a single JSON file
    getTableData() {
        return this.http.get('...').map((res: Response) => res.json());
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读