当我尝试创建用户时,我收到以下错误:错误:Firebase.createUser失败:第一个参数必须是有效对象。
var myapp = angular.module('myapp', ['ui.router', 'firebase']);
myapp.config(['$stateProvider', function ($stateProvider) {
$stateProvider.state('home', {
url: '/',
templateUrl: 'templates/welcome.html',
controller: 'home.controller'
});
$stateProvider.state('createUser', {
url: '/createUser',
templateUrl: 'templates/createUser.html'
});
$stateProvider.state('login', {
url: '/login',
templateUrl: 'templates/login.html'
});
}]);
myapp.run(function ($rootScope, $state, $stateParams) {
// $rootScope.$state = $state;
// $rootScope.$stateParams = $stateParams;
// $state.transitionTo('home');
//console.log("runnin'");
});
myapp.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
var ref = new Firebase("https://amber-inferno-5836.firebaseIO.com/");
return $firebaseAuth(ref);
}
]);
myapp.controller('app.controller', ['$scope', '$state', '$stateParams', 'Auth', function ($scope, $state, $stateParams, auth) {
$scope.login = {};
$scope.createUser = function() {
auth.$createUser($scope.user)
.then(function(userData) {
console.log("User " + userData.uid + " created successfully!");
})
.catch(function(error) {
console.error("Error: ", error);
});
};
$scope.login = function() {
auth.$authWithPassword($scope.login).then(function(authData) {
// $state.go('');
// console.log("Logged in as:", authData.uid);
}).catch(function(error) {
console.error("Authentication failed:", error);
});
};
$scope.logout = function() {
auth.$unauth();
};
auth.$onAuth(function(authData) {
if (authData) {
$scope.activeUser = authData;
$scope.login = {};
console.log("Logged in as:", authData.uid);
} else {
$scope.activeUser = false;
console.log("Logged out");
$state.go('home');
}
});
}]);
myapp.controller('home.controller', ['$scope', '$state', '$stateParams', function ($scope, $state, $stateParams) {
$scope.statename = $state.current.name;
$scope.message = 'Welcome';
console.log("home.controller initialized! current state: " + $scope.statename);
// $state.go("home");
}]);
以下是html的片段:
<div class="new-account-panel">
<div class="panel-body">
<form ng-submit="createUser()">
<input class="inputBox" type="text" name="email" id="email" ng-model="user.email" placeholder="Email" />
<br>
<input class="inputBox" type="password" name="Password" id="password" ng-model="user.password" placeholder="Password" />
<br>
<button type="submit">Create User</button>
</form>
</div>
</div>
这是index.html:
<!DOCTYPE html>
<html ng-app="myapp">
<head lang="en">
<meta charset="UTF-8">
<title>Bloc Base Project</title>
<link rel="stylesheet" href="/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Lato:100,300,400' rel='stylesheet' type='text/css'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.8/angular-ui-router.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.1.1/angularfire.min.js"></script>
<script src="/js/app.js"></script>
</head>
<body ng-controller="app.controller">
<div class="wrapper">
<header>
<h1>B<span>loc</span>I<span>t</span>O<span>ff</span></h1>
<h3>- Task Management Simplified -</h3>
</header>
<div class="login">
<h4><a ui-sref="login" href="/login">Login</a></h4>
<h4><a ui-sref="createUser" href="/createUser">Create new Account</a></h4>
<h4 ng-if="activeUser"><a ng-click="logout()" href="#">Log Out</a></h4>
</div>
<div ui-view="welcome"></div>
<div ui-view>
</div>
</div>
</body>
</html>
我还是很陌生,任何帮助都会非常感激。此外,我已经检查过,登录和退出仍然可以正常运行。我确信它很简单,但我很难搞清楚它。感谢。