1

After update my app to angular2 to RC4 I am reciving this error. I have LoginService injected into AppComponent in new webpack starter bundle.

I was trying to inlcude AppComponent in routes, but it won't works. Also I was including LoginService inside index.ts with APP_PROVIDERS but I am getting another error

Invalid provider - only instances of Provider and Type are allowed, got: undefined

Also putting LoginService in bootstrap, but without effect.

What is wrong with Angular2 in RC4 ? Components are not in the tree anymore?

This is my router config for router "3.0.0-beta.2" :

export const routes: RouterConfig = [
  { path: '', component: StartPageComponent },
  { path: 'login', component: StartPageComponent },
  {
    path: 'dashboard', component: 'DashboardComponent',
    canActivate: [WebpackAsyncRoute],
    children: [
      { path: '', component: 'ContentDesktopComponent' }  // must be included
    ]
  },
  { path: '**', component: NoContent }

];

And I wanna have LoginService available for every routes.

My app.component looks like this:

@Component({
  selector: 'app',
  pipes: [],    
  providers: [LoginService, SearchService, TasksService],   
  directives: [RouterActive],
  encapsulation: ViewEncapsulation.None,
  styles: [
    require('!raw!normalize.css'),
    require('!raw!../assets/css/animate.css'),
    require('./app.component.scss')
  ],
  template: require('./app.component.html')
})
export class App {

  constructor(private translate: TranslateService,
    public appState: AppState) {

    Resource.map(ENDPOINTS.API.toString(), 'http://localhost:3002/api');
    let userLang = navigator.language.split('-')[0]; // use navigator lang if available
    userLang = /(fr|en)/gi.test(userLang) ? userLang : 'pl';
    translate.setDefaultLang('en');
    translate.use('pl');

  }

  ngOnInit() {

  }

}

provider are not available for routers... now... in rc4

LoginService:

@Injectable()
export class LoginService {

    private user: User = <User>{
        avatar_url: '/assets/img/avatars/u6.png'
    };

    constructor(private rest: Resource<ENDPOINTS, User, User[]>) {
        this.rest.add(ENDPOINTS.API, 'users');
    }
Dariusz Filipiak
  • 2,858
  • 5
  • 28
  • 39

1 Answers1

0

You need to provide TranslateService and AppState somewhere, either in bootstrap(...) or in @Component(..., providers: [...]

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Still: `One or more of providers for "App" were not defined: [?, SearchService, TasksService, TranslateService].` – Dariusz Filipiak Jul 22 '16 at 10:41
  • Looks like `LoginService` is not properly imported. Please update your question with the code you have currently. I can't know what you have changed. – Günter Zöchbauer Jul 22 '16 at 10:42
  • its weir error becouse now I have 4 providers: `providers: [LoginService, SearchService, TasksService, TranslateService], ` – Dariusz Filipiak Jul 22 '16 at 10:43
  • Okej the problem is with my extension ng2-rest https://github.com/darekf77/ng2-rest .... Even when **Resource** is in provider I am still getting this error (I have Resource in bootstrap already). My question is now there any problem with generic class services like **Resource** in RC4 ? – Dariusz Filipiak Jul 22 '16 at 10:49
  • Where and how do you provide `Resource`? – Günter Zöchbauer Jul 22 '16 at 11:09
  • Okej the problem was with ENUMS. When I change ENDPOINT **enum** to **type** it works (here: private rest: Resource ) – Dariusz Filipiak Jul 22 '16 at 11:57