javascript - 如何使用 AngularFire 调用 Firebase JS 方法

标签 javascript angularjs firebase angularfire firebase-authentication

我正在使用 AngularFire (Firebase 和 AngularJS 之间的接口(interface)库)。

我想调用 javascript 方法 sendEmailVerification()在我的 Angular 代码中。当我实现下面的代码时,我收到一条错误消息:$scope.authObj.sendEmailVerification is not a function. 这可能是因为我试图在 AngularJS (AngularFire) 中使用 javascript 方法。

有没有办法通过 AngularFire 来使用 Javascript 方法?

$scope.signUp = function() {

  $scope.authObj.$createUserWithEmailAndPassword($scope.email, $scope.password)
    .then(function(firebaseUser) {

      $scope.sendVerifyEmail();

    }).catch(function(error) {
      console.error("Error: ", error);
    });
}

$scope.sendVerifyEmail = function(){
  $scope.authObj.sendEmailVerification();
}

最佳答案

我刚刚发现我可以使用所需的 Firebase 方法在 app.controller 外部编写一个 javascript 函数,并从 app.controller 内部调用它,即在 Angular 方法内部调用它。

下面是我更新的代码

// The below JS function written outside app.controller
function sendVerifyEmail(firebaseUser){
  firebaseUser.sendEmailVerification();
}

上面的JS函数是从下面的angular函数调用的

$scope.signUp = function() {

  $scope.authObj.$createUserWithEmailAndPassword($scope.email, $scope.password)
    .then(function(firebaseUser) {

      sendVerifyEmail(firebaseUser);

    }).catch(function(error) {
      console.error("Error: ", error);
    });
}

关于javascript - 如何使用 AngularFire 调用 Firebase JS 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38669930/

相关文章:

javascript - NodeJS 应用程序在多次请求后崩溃

javascript - 使用 Google 电子表格中的值数组填充 jQuery 自动完成列表

javascript - Chrome 扩展 : grab all cross domain cookies under the url tab?

asp.net - CORS 发出相同的 Controller ,一种方法可以,另一种方法不行

swift - 类型 'StorageMetadata' 的值没有成员 'downloadURL'

ios - Swift iOS - 在 View 更改后使用哪个 viewController 生命周期事件将数据发送到 Firebase

javascript - jQuery/CSS - 整个 Div 可点击,悬停时激活标签悬停状态

javascript - 获取模板并将其附加到 DOM 后的 UI-Router Hook

angularjs - 更新函数仅在数据库中存储名称属性而不是 url 属性,而是存储未定义

ios - 单击动态链接时深层链接不包含有效的必需参数