带有Firebase身份验证的AngularJS

时间:2018-08-01 08:03:47

标签: angularjs firebase-authentication

我正在尝试使用AngularJS和firebase身份验证(电子邮件和密码)创建用户登录页面。

我在网上查找了一些教程并编写了代码,但似乎不起作用。

下面是我的代码。

1)page.html

X

2)index.html

np.sum(np.multiply(A,X))

3)controller.js

  <ion-view id="page646">
  <ion-content padding="true" class="has-header">

  <form>
   <label class="item item-input">
    <span class="input-label">EMAIL</span>
    <input type="email" placeholder="" ng-model="user.email">
  </label>
  <label class="item item-input">
    <span class="input-label">PASSWORD</span>
    <input type="text" placeholder="" ng-model="user.pass">
  </label>

  <div style="margin-right:-20px;">
    <button style="left:-10px;" class="button button-positive button-full"ng-click="signIn()">SIGN IN</button>
  </div>
  </form>

</ion-content>
</ion-view> 

4)Firebase-aaa.js

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<script src="lib/ionic/js/ionic.bundle.js"></script>

  <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase.js"> 
  </script>
  <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-app.js"> 
  </script>
  <script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-auth.js"> 
  </script>


   <!-- AngularFire -->
   <script 
   src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"> 
   </script>


<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<link href="lib/ionic/css/ionic.css" rel="stylesheet">

<style type="text/css">
  .platform-ios .manual-ios-statusbar-padding{
    padding-top:20px;
  }
  .manual-remove-top-padding{
    padding-top:0px; 
  }
  .manual-remove-top-padding .scroll{
    padding-top:0px !important;
  }
  ion-list.manual-list-fullwidth div.list, .list.card.manual-card-fullwidth {
    margin-left:-10px;
    margin-right:-10px;
  }
  ion-list.manual-list-fullwidth div.list > .item, .list.card.manual-card-fullwidth > .item {
    border-radius:0px;
    border-left:0px;
    border-right: 0px;
  }
  .show-list-numbers-and-dots ul{
    list-style-type: disc;
    padding-left:40px;
  }
  .show-list-numbers-and-dots ol{
    list-style-type: decimal;
    padding-left:40px;
  }
</style>

<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/routes.js"></script>
<script src="js/directives.js"></script>
<script src="js/services.js"></script>
<script src="lib/ngCordova/"></script>

</head>
<body ng-app="app" animation="slide-left-right-ios7">
<div>
<div>
<ion-nav-bar class="bar-stable">
  <ion-nav-back-button></ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view></ion-nav-view>
</div>
</div>
</body>
</html>

当我尝试输入代码时,我“未登录”。 我正在看Firebase身份验证教程,有一部分他没有启用电子邮件和密码身份验证。在尝试代码时,控制台出现错误,指出Firebase电子邮件和密码身份验证尚未启用。 我试图禁用我的,希望看到同样的错误,但结果却并非如此。它只说“未登录”。 我找不到问题所在。 我的问题是,即使signInWithEmailAndPassword,我也如何获得成功。

1 个答案:

答案 0 :(得分:0)

您需要将这些位移出登录功能

 $scope.user = {
        email:"",
        pass:"",
    }

它将对象“ user”重新初始化为空值,并且onAuthStateChanged也应位于外部。