【问题标题】:How to link google firebase to ionic's controller.js file?如何将 google firebase 链接到 ionic 的 controller.js 文件?
【发布时间】:2016-09-19 19:19:16
【问题描述】:

我是一名学生,我的团队参加了写作应用比赛。只有这么少的编码知识,我们无法找出以下代码的问题:

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>

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

【问题讨论】:

    标签: javascript angularjs ionic-framework firebase-authentication


    【解决方案1】:

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

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

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

    【讨论】:

    • @GeoffreyLau:这是解决方案吗?如果是这样,请单击勾选标记接受它 - 这就是我们在这里感谢人们的方式。如果没有,请添加您自己的答案,因为它可能对未来的读者有所帮助。
    【解决方案2】:

    我没有看到你的路线,也许问题就在那里。您需要将视图与控制器“链接”。这是一个例子:

    routes.js

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

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2016-10-18
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-23
      • 2012-11-24
      • 1970-01-01
      相关资源
      最近更新 更多