简体   繁体   中英

Uncaught (in promise): Error: No provider for Credentials?

What does it mean?

I have import:

import {Credentials} from '../_models/credentials/credentials.model';

And constructor:

constructor(private router: Router,
private credential: Credentials){
}

You cant inject a model class in the constructor. It needs to be @Injectable() and set as a provider to be used by Angular's DI.

Change your constructor to:

constructor(private router: Router)

You cannot inject a model in the constructor. Define credential as a class variable.

import {Credentials} from '../_models/credentials/credentials.model';
// ... 
//
private credential: Credentials;
// ... ...
//
constructor(private router: Router){ }

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