Angularfire: Can't resolve all parameters for AuthService: (AngularFire, ?, ?).

Created on 16 Aug 2016  路  1Comment  路  Source: angular/angularfire

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));
  }

}

Most helpful comment

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

>All comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fisherds picture fisherds  路  3Comments

Leanvitale picture Leanvitale  路  3Comments

sharomet picture sharomet  路  3Comments

Sun3 picture Sun3  路  3Comments

jteplitz picture jteplitz  路  3Comments