I am trying to put all of my AngularFire Authentication code in one service however when I use it I get this error: Can't resolve all parameters for AuthService: (AngularFire, ?, ?).
I am running on AngularFire@next, RC.5, Angular-cli Webpack 2
Here is my AuthService code:
import { Injectable } from '@angular/core';
import { AngularFire, AuthMethods, AuthProviders} from 'angularfire2';
@Injectable()
export class AuthService {
constructor(private af: AngularFire, public error: String, public uid: String) {
this.af.auth.subscribe(auth => {this.uid = auth.uid; });
}
googleLogin() {
this.af.auth.login();
}
passwordLogin(Email, Password) {
this.af.auth.login(
{email: Email, password: Password},
{provider: AuthProviders.Password, method: AuthMethods.Password}
).catch(err => this.error = err.toString().substring(7));
}
}
The problem is with your error and uid parameters.
constructor(private af: AngularFire, public error: String, public uid: String) {
this.af.auth.subscribe(auth => {this.uid = auth.uid; });
}
You need to create a way for those to be injected either with a @Inject() or through a Token.
http://blog.thoughtram.io/angular/2016/05/23/opaque-tokens-in-angular-2.html
http://blog.thoughtram.io/angular2/2015/11/23/multi-providers-in-angular-2.html
Most helpful comment
The problem is with your
erroranduidparameters.You need to create a way for those to be injected either with a
@Inject()or through a Token.http://blog.thoughtram.io/angular/2016/05/23/opaque-tokens-in-angular-2.html
http://blog.thoughtram.io/angular2/2015/11/23/multi-providers-in-angular-2.html