0

私は学生であり、私のチームはライティングアプリのコンテストに参加しました。私たちは、次のコードで問題を把握できなかった知識をコーディングするだけで、このような少量:Googleのfirebaseをionicのcontroller.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-モデルを使用しました。

<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> 

問題の原因はどこにあり、どのように修正するのか教えてください。

答えて

0

あなたのボタンのクリックイベントがあなたの関数にバインドされていない、あなたのコントローラで以下のように実行する必要があります。

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

$scopeは、角度やイオン、世界のビューとモデルの橋です。

+0

ありがとうございました。問題を解決しました。 –

+0

@ GeoffreyLau:これは解決策ですか?もしそうなら、ティックマークをクリックしてそれを受け入れてください - それは我々が人々にここで感謝する方法です。そうでない場合は、将来の読者に役立つかもしれないので、あなた自身の答えを加えてください。 – halfer

0

ルートが表示されず、問題が発生している可能性があります。コントローラとのビューを「リンク」する必要があります。次に例を示します。

routes.js

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

はそれがお役に立てば幸いです。

関連する問題