简体   繁体   English

Angular2:没有提供程序<custom service>

[英]Angular2: No Provider for <custom service>

I had working code with alpha44 but the upgrade to beta is defeating me. 我曾经使用过alpha44的代码,但是升级到Beta版却败给了我。 I get this error: 我收到此错误:

EXCEPTION: No provider for e! (HomeCmp -> RestosSvc -> e)

I have include RestosSvc in my bootstrap, and the file can be found. 我的引导程序中包含RestosSvc,并且可以找到该文件。 This is part of my HomeCmp 这是我的HomeCmp的一部分

import {Component} from 'angular2/core';

import { Resto, RestosSvc } from '../../services/RestosSvc';


@Component({
  selector: 'home',
  templateUrl: './components/home/home.html',
  styleUrls: ['./components/home/home.css'],
  directives: [FiltersCmp, ListCmp, MapCmp],
  providers: [RestosSvc]
})
export class HomeCmp {
  recommendations: Array<Resto> = [];
  presetCrits: Object;
  selectedResto: number = -1;
  top5: boolean;

  constructor(public restos: RestosSvc, urlCrits: RouteParams, public router: Router) {

And here is the RestoSvc 这是RestoSvc

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

@Injectable()
export class RestosSvc {
    http: Http;

    constructor(http:Http) {

What am I missing? 我想念什么?

We faced the same issue because we had mangle set to true during minification. 我们遇到了同样的问题,因为在缩小过程中将mangle设置为true。 The no provider for e! 没有e!提供者e! gave one of my colleagues a hint that this might be an issue with minification. 给我的一位同事暗示这可能是缩小问题。 Check your minified files and make sure that you use the ones that were generated with mangle set to false. 检查缩小的文件,并确保您使用将mangle设置为false生成的文件。 This is an ongoing issue and is scheduled to be fixed in a couple of weeks 这是一个持续存在的问题,计划在几周内解决

More info here: https://github.com/angular/angular/issues/7306 https://github.com/AngularClass/angular2-webpack-starter/issues/262 此处的更多信息: https : //github.com/angular/angular/issues/7306 https://github.com/AngularClass/angular2-webpack-starter/issues/262

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM