2016-04-16 69 views
0

在我的索引我导入所有库,我做我的firebase的所有配置也只有登录部分不工作,但基本插入部分与firebase阵列woking,当我添加firebase AUTH它没有工作,我试试这个只有一个return语句还,我需要工作两个火力点权威性和火力点阵列,,firebase登录与离子不工作

的login.html

<ion-view title="Login" class="login"> 
    <ion-content overflow-scroll="true" padding="true" scroll="false" class="has-header"> 
    <form class="list"> 
     <ion-list> 
      <label class="item item-input"> 
       <span class="input-label">Username</span> 
       <input type="text" placeholder=""ng-model="username"> 
      </label> 
      <label class="item item-input"> 
       <span class="input-label">Password</span> 
       <input type="password" placeholder=""ng-model="password"> 
      </label> 
     </ion-list> 
     <div class="spacer" style="width: 300px; height: 31px;"></div> 
     <a id="login-button1" class="button button-block" ng-click="login()" > Log in</a> 
     <a id="reg-button1" class="button button-block" ng-click="register(username,password)" > register</a> 

     <a ui-sref="menu.signup" id="login-button4" class="button button-positive button-block button-clear">Or create an account</a> 

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

app.js

angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.directives','app.services','firebase','angularMoment']) 

.run(function($ionicPlatform) { 

$ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if(window.StatusBar) { 
    // org.apache.cordova.statusbar required 
    StatusBar.styleDefault(); 
    } 
}); 

})

service.js

angular.module('app.services', []) 
    .factory('CarInfor', function($firebaseAuth,$firebaseArray){ 
     var itemsRef = new Firebase('https://mycar12.firebaseio.com/'); 
     return $firebaseAuth(itemsRef); 
     return $firebaseArray(itemsRef); 
}) 

登录controller.js

angular.module('app.controllers', []) 

.controller('loginCtrl', function($scope,CarInfor) { 
    $scope.login = function(data) { 
     var fbAuth = $firebaseAuth(CarInfor); 
     fbAuth.$authWithPassword({ 

      email: username, 
      password: password 
     }) 
     .then(function(authData) { 
      $location.path("/myads"); 
     }) 
     .catch(function(error) { 
      console.error("ERROR: " + error); 
     }); 
    } 
    $scope.register = function(data) { 
      var fbAuth = $firebaseAuth(CarInfor); 
      fbAuth.$createUser({email: username, password: password}).then(function() { 
       return fbAuth.$authWithPassword({ 
        email: username, 
        password: password 
       }); 
      }).then(function(authData) { 
       $location.path("/myads"); 
      }).catch(function(error) { 
       console.error("ERROR " + error); 
      }); 
     } 

})

+1

您的** service.js 2'returns' **。第二个将永远达不到。 –

+0

另外,你没有提供数据的路径,应该是'https://mycar12.firebaseios.com/youdatapath' –

+0

那么如何使用$ firebaseAuth和$ firebaseArray –

回答

0

查看完整的codepen这里.... http://codepen.io/aaronksaunders/pen/bpMrdr

一定要设置firebasepath

.value('ExampleConst', { 
    'FBBasePath': 'https://[YOUR-APP-NAME].firebaseio.com/' 
    }) 

HTML无法将数据送回正确

<ion-content class="has-subheader"> 
    <form class="list"> 
     <ion-list> 
     <label class="item item-input"> 
      <span class="input-label">Username</span> 
      <input type="text" placeholder=""ng-model="credentials.email"> 
     </label> 
     <label class="item item-input"> 
      <span class="input-label">Password</span> 
      <input type="password" placeholder=""ng-model="credentials.password"> 
     </label> 
     </ion-list> 
     <div class="spacer" style="width: 300px; height: 31px;"></div> 
     <a id="login-button1" class="button button-block" ng-click="login(credentials)"> Log in</a> 
     <a id="reg-button1" class="button button-block" ng-click="register(credentials)"> register</a> 
    </form> 
    </ion-content> 

登录功能是缺少合适的模型

.controller('LoginCtrl', function($scope, $state, $firebaseAuth, ExampleConst) { 

    $scope.credentials = { 
    email: "", 
    password: "" 
    } 

    $scope.login = function(_credentials) { 

    debugger; 
    var fbRef = new Firebase(ExampleConst.FBBasePath) 
    var fbAuth = $firebaseAuth(fbRef); 
    fbAuth.$authWithPassword(_credentials) 
    .then(function(authData) { 
     console.log("Authentication Data:", authData) 
     $state.go("home",{}); 
    }) 
    .catch(function(error) { 
     console.error("ERROR: " + error); 
     alert(error) 
    }); 
} 
0

此方法已过时,看看你的错误信息。

此外,原始来源:

[火力地堡文档] [2]