【问题标题】:How to declare AuthService inside a module? [closed]如何在模块中声明 AuthService? [关闭]
【发布时间】:2020-04-18 12:57:23
【问题描述】:

我尝试使用ng g s core/auth --m=coreng generate service core/auth --m=core 在我的模块core 中创建服务,但两者均无效。 它给了我这个错误:未知选项:'--m' 然后,我通过将文件命名为 auth.service.ts 在核心模块中手动创建它,并在其中编写了以下代码:

import { Injectable } from '@angular/core'
import { AngularFireAuth } from '@angular/fire/auth'
import * as firebase from 'firebase/app'

@Injectable()
export class AuthService {
  constructor(public afAuth: AngularFireAuth){}

  login() {
    this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
  }
  logout() {
    this.afAuth.auth.signOut()
  }
}

但是现在,我的导航栏组件无法正常工作,并且我的整个 Angular 应用程序都没有加载。我已经搜索了很多,但没有任何帮助。请指导我。

【问题讨论】:

  • 简单使用:ng g s auth
  • 你能指导我如何将它导入到我的共享模块中的导航栏组件中吗?
  • 我已经提供了一个答案,通过执行这些步骤,您应该能够在相应的模块中创建服务。
  • 如果您要使用m 选项来指示生成服务时要使用的模块,您只使用一个破折号:-m,而不是两个:--m。使用完整选项名称时需要两个破折号:--module

标签: javascript angular typescript firebase service


【解决方案1】:

执行以下步骤:

  1. cd 到要创建服务的模块的路径。
  2. 输入:ng generate service auth

【讨论】:

  • 非常感谢。它就像一个魅力。我不知道我们可以使用这种方法来做到这一点:)
猜你喜欢
  • 1970-01-01
  • 2014-04-30
  • 2013-03-08
  • 1970-01-01
  • 2022-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多