Angularjs AngularFire createUser示例不在Firebase网站之外工作
在尝试学习AngularFire的过程中,我一直在玩弄AngularFire的用户身份验证方法。在Firebase网站上,给出了一个示例,当我在适当的位置插入Firebase地址时,它可以工作。当我将代码复制并粘贴到Notepad++中并尝试以这种方式运行它时,HTML可以工作,但Javascript都不能。我在Javascript中添加了一个警报框,打开页面时,警报框弹出,但JS的其余部分都不起作用。我觉得我错过了一些非常明显的东西。我做错了什么 谢谢你的帮助 我的代码如下:Angularjs AngularFire createUser示例不在Firebase网站之外工作,angularjs,firebase,angularfire,Angularjs,Firebase,Angularfire,在尝试学习AngularFire的过程中,我一直在玩弄AngularFire的用户身份验证方法。在Firebase网站上,给出了一个示例,当我在适当的位置插入Firebase地址时,它可以工作。当我将代码复制并粘贴到Notepad++中并尝试以这种方式运行它时,HTML可以工作,但Javascript都不能。我在Javascript中添加了一个警报框,打开页面时,警报框弹出,但JS的其余部分都不起作用。我觉得我错过了一些非常明显的东西。我做错了什么 谢谢你的帮助 我的代码如下: <!doc
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="https://cdn.firebase.com/js/client/2.2.2/firebase.js"></script>
<script src="https://cdn.firebase.com/libs/angularfire/1.0.0/angularfire.min.js"> </script>
</head>
<body>
<script>
var app = angular.module("sampleApp", ["firebase"]);
// let's create a re-usable factory that generates the $firebaseAuth instance
app.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
var ref = new Firebase("https://xxxxx.firebaseio.com/?page=Auth");
return $firebaseAuth(ref);
}
]);
// and use it in our controller
app.controller("SampleCtrl", ["$scope", "Auth",
function($scope, Auth) {
$scope.createUser = function() {
$scope.message = null;
$scope.error = null;
Auth.$createUser({
email: $scope.email,
password: $scope.password
}).then(function(userData) {
$scope.message = "User created with uid: " + userData.uid;
}).catch(function(error) {
$scope.error = error;
});
};
$scope.removeUser = function() {
$scope.message = null;
$scope.error = null;
Auth.$removeUser({
email: $scope.email,
password: $scope.password
}).then(function() {
$scope.message = "User removed";
}).catch(function(error) {
$scope.error = error;
});
};
}
]);
</script>
<div ng-app="sampleApp" ng-controller="SampleCtrl">
Email: <input type="text" ng-model="email">
Password: <input type="text" ng-model="password">
<br><br>
<button ng-click="createUser()">Create User</button>
<br><br>
<button ng-click="removeUser()">Remove User</button>
<p ng-if="message">Message: <strong>{{ message }}</strong></p>
<p ng-if="error">Error: <strong>{{ error }}</strong></p>
</div>
</body>
</html>
var-app=angular.module(“sampleApp”[“firebase”]);
//让我们创建一个可重用的工厂来生成$firebaseAuth实例
app.factory(“Auth”,[“$firebaseAuth”,
函数($firebaseAuth){
var ref=新的火基(“https://xxxxx.firebaseio.com/?page=Auth");
返回$firebaseAuth(ref);
}
]);
//并在我们的控制器中使用它
app.controller(“SampleCtrl”、[“$scope”、“Auth”,
函数($scope,Auth){
$scope.createUser=function(){
$scope.message=null;
$scope.error=null;
Auth.$createUser({
电子邮件:$scope.email,
密码:$scope.password
}).then(函数(用户数据){
$scope.message=“使用uid创建的用户:”+userData.uid;
}).catch(函数(错误){
$scope.error=错误;
});
};
$scope.removeUser=函数(){
$scope.message=null;
$scope.error=null;
授权$removeUser({
电子邮件:$scope.email,
密码:$scope.password
}).然后(函数(){
$scope.message=“用户已删除”;
}).catch(函数(错误){
$scope.error=错误;
});
};
}
]);
电邮:
密码:
创建用户
删除用户
消息:{{message}
错误:{{error}
我认为发生的事情是,您在html中使用了两次ng app指令。如果您查看,第一个ng应用程序标记作为应用程序自动引导,则必须手动加载任何其他ng应用程序。此外,您不能在页面中嵌套应用程序。当我试图运行您的应用程序时,SampleCtrl控制器未定义
我已经删除了第一个ng应用程序指令,您的其余代码在我创建的应用程序中似乎运行良好
<!DOCTYPE html>
<!--
ng-app directive is already delclared in the body, removing this one
<html ng-app>
-->
<html>
<head>
...
</head>
<body>
<div ng-app="sampleApp" ng-controller="SampleCtrl">
...
</body>
</html>
...
...
我认为发生的事情是,您在html中使用了两次ng app指令。如果您查看,第一个ng应用程序标记作为应用程序自动引导,则必须手动加载任何其他ng应用程序。此外,您不能在页面中嵌套应用程序。当我试图运行您的应用程序时,SampleCtrl控制器未定义
我已经删除了第一个ng应用程序指令,您的其余代码在我创建的应用程序中似乎运行良好
<!DOCTYPE html>
<!--
ng-app directive is already delclared in the body, removing this one
<html ng-app>
-->
<html>
<head>
...
</head>
<body>
<div ng-app="sampleApp" ng-controller="SampleCtrl">
...
</body>
</html>
...
...
我认为发生的事情是,您在html中使用了两次ng app指令。如果您查看,第一个ng应用程序标记作为应用程序自动引导,则必须手动加载任何其他ng应用程序。此外,您不能在页面中嵌套应用程序。当我试图运行您的应用程序时,SampleCtrl控制器未定义
我已经删除了第一个ng应用程序指令,您的其余代码在我创建的应用程序中似乎运行良好
<!DOCTYPE html>
<!--
ng-app directive is already delclared in the body, removing this one
<html ng-app>
-->
<html>
<head>
...
</head>
<body>
<div ng-app="sampleApp" ng-controller="SampleCtrl">
...
</body>
</html>
...
...
我认为发生的事情是,您在html中使用了两次ng app指令。如果您查看,第一个ng应用程序标记作为应用程序自动引导,则必须手动加载任何其他ng应用程序。此外,您不能在页面中嵌套应用程序。当我试图运行您的应用程序时,SampleCtrl控制器未定义
我已经删除了第一个ng应用程序指令,您的其余代码在我创建的应用程序中似乎运行良好
<!DOCTYPE html>
<!--
ng-app directive is already delclared in the body, removing this one
<html ng-app>
-->
<html>
<head>
...
</head>
<body>
<div ng-app="sampleApp" ng-controller="SampleCtrl">
...
</body>
</html>
...
...