我正在製作網絡應用程序,並且在從輸入文本中獲取值時遇到問題。如何從輸入中獲取它們?Angular,angularfire - 在控制器中獲得價值
var app = angular.module('app', ['ngRoute', 'firebase']);
app.controller("AuthCtrl", function($scope, $firebaseObject) {
var ref = firebase.database().ref();
$scope.data = $firebaseObject(ref);
});
app.controller("AuthCtrl", ["$scope", "$firebaseAuth",
function($scope, $firebaseAuth) {
$scope.login = function($scope) {
var login = '';
var pass = '';
$scope.authObj = $firebaseAuth();
$scope.authObj.$signInWithEmailAndPassword(login, pass)
.then(function(firebaseUser) {
console.log("Signed in as:", firebaseUser.uid);
}).catch(function(error) {
console.error("Authentication failed:", error);
});
}
}
]);
THE SOLUTION: 錯誤的控制器使用。 從AuthCtrl到loginCtrl一切正常! 一切都因爲我使用ngRoute。
app.controller("logintCtrl", ["$scope", "$firebaseAuth",
function($scope, $firebaseAuth) {
$scope.login = function($scope) {
var login = '';
var pass = '';
$scope.authObj = $firebaseAuth();
$scope.authObj.$signInWithEmailAndPassword(login, pass)
.then(function(firebaseUser) {
console.log("Signed in as:", firebaseUser.uid);
}).catch(function(error) {
console.error("Authentication failed:", error);
});
}
}
]);
請參閱[AngularJS開發人員指南 - 表單(簡單表單)](https://docs.angularjs.org/guide/forms#simple-form)。 * [ngModel指令](https://docs.angularjs.org/api/ng/directive/ngModel)通過將模型同步到視圖以及查看模型來提供雙向數據綁定。* – georgeawg
Angular 1.6.3,Firebase 3.8.0,Angularefire 2.3.0 –
我正在關注這個:https://github.com/firebase/angularfire/blob/master/docs/guide/user-auth.md#signing-用戶,在 –