【问题标题】:Cannot resolve all parameters for 'TypeDecorator'(?) .Make sure that typedecarator is decaorated with @injectable无法解析 'TypeDecorator'(?) 的所有参数。确保使用 @injectable 对 typedecorator 进行修饰
【发布时间】:2016-07-13 04:35:56
【问题描述】:

在修复如何导入添加到应用程序的文件夹后,我收到此错误。

我的应用结构

我的“app.ts”包括

import { bootstrap } from "@angular/platform-browser-dynamic";
import { Component,Inject } from "@angular/core";
import {JsonService} from "services";
import {Http,HTTP_PROVIDERS} from "@angular/http";
import {provide} from '@angular/core';
@Component({
  selector: 'hello-world',
  template: `
  <div>
    Hello world
  </div>
  `,
})
class HelloWorld {
  constructor(@Inject(JsonService) private service :JsonService){

  }
}

bootstrap(HelloWorld,[Http,HTTP_PROVIDERS,JsonService]);

我的服务

import {Injectable,Inject} from "@angular/core";
import {Http} from "@angular/http";


    @Injectable
    export class JsonService {
        constructor(@Inject(Http) private http: Http) {

        }

    }

我的system.js.config文件如下

 var map = {
    'app':                        'app',
    'rxjs':                       'node_modules/rxjs',
    '@angular':                   'node_modules/@angular',
    'services':                   'services',
    'models':                     'models'
  };

  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'rxjs': { defaultExtension: 'js' },
     'models':                       { main: 'index.js',  defaultExtension: 'js' },
     'services':                       { main: 'index.js',  defaultExtension: 'js' }
  };

  var packageNames = [
    '@angular/common',
    '@angular/compiler',
    '@angular/core',
    '@angular/http',
    '@angular/platform-browser',
    '@angular/platform-browser-dynamic',
    '@angular/router',
    '@angular/router-deprecated',
    '@angular/testing',
    '@angular/upgrade',
    'services',
    'models'
  ];

一开始我收到 404 错误,在修改 system.js 并添加服务和模型后我的服务丢失,我收到此错误

仍然得到这个 404

错误:无法解析“TypeDecorator”的所有参数(?)。确保所有参数都用 Inject 修饰或具有有效的类型注释,并且 'TypeDecorator' 用 Injectable 修饰

完整代码链接https://1drv.ms/u/s!Ai1EHDfZ96E2wij-MtwLHdCI-hVI

【问题讨论】:

    标签: dependency-injection angular inject angular2-services


    【解决方案1】:

    为我解决了这个错误的是 JGW96 在this thread 中的评论,在 Angular 2 中你不能将服务注入服务。我正在为一些 JSON 数据创建一个视图模块,并将订阅拆分为一个视图模块。一旦我将它移回主服务模块,然后将该主服务作为提供程序包含在视图组件中,装饰器错误就解决了。

    【讨论】:

      猜你喜欢
      • 2018-05-18
      • 2018-08-22
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 2017-02-12
      相关资源
      最近更新 更多