简体   繁体   中英

Angular2: No Provider for <custom service>

I had working code with alpha44 but the upgrade to beta is defeating me. 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. This is part of my 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

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. The no provider for 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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