如何将谷歌Firebase链接到ionic的控制器.js文件?



我是一名学生,我的团队参加了一个写作应用程序竞赛。仅凭如此少量的编码知识,我们无法找出以下代码的问题:

angular.module('app.controllers', [])
.controller('studentLoginCtrl', function($scope) {
function login(username,password) {
var ref = new Firebase("https://project-2767910204862952587.firebaseio.com");
ref.authWithPassword({
  email    : username,
  password : password
}, function(error, authData) {
  if (error) {
    console.log("Login Failed!", error);
  } else {
    console.log("Authenticated successfully with payload:", authData);
    window.location = "/SFront";
  }
});

}
})

我们已经查找了很多教程和大量的试验和错误。运行代码时没有显示错误,但它没有执行任何操作。

链接到操作的按钮使用以下代码:

<button ng-click="login(username, password)" id="studentLogin-button7" style="font-weight:;" class=" button button-balanced  button-block icon-left ion-android-checkmark-circle ">Log in</button>

我已经使用 ng-model 来指导用户名和密码数据。

<ion-list id="studentLogin-list2" class=" ">
                <label class="item item-input " id="studentLogin-input4">
                    <span class="input-label">Username</span>
                    <input type="email" placeholder="Email" ng-model="username">
                </label>
                <label class="item item-input " id="studentLogin-input5">
                    <span class="input-label">Password</span>
                    <input type="password" placeholder="Password" ng-model="password">
                </label>

任何专家能否告诉我们问题的根源在哪里以及如何解决这个问题?

按钮的单击事件未绑定到函数,您应该在控制器中执行以下操作:

$scope.username = '';
$scope.password = '';
$scope.login = function(username,password) {
  //your implemention here
}

$scope是角度和离子世界中的观点和模型的桥梁。

我没有看到您的路线,也许问题就在那里。您需要将视图与控制器"链接"。下面是一个示例:

路线.js

 .config(function($stateProvider, $urlRouterProvider) {
      $stateProvider
    .state('signup', {
        url: "/signup",
        templateUrl: "views/signup.html",
        controller: "studentLoginCtrl"
      })

希望对您有所帮助。

最新更新