如何通过将用户信息添加到控制器中来获取用户信息?
我希望从角度工厂访问用户详细信息,例如电子邮件,姓名,年龄等,以便我可以在控制器上显示这些详细信息,例如姓名,年龄,电子邮件等。
我尝试过:
工厂
angular.module('...')
.factory('UserDataService', function($q, $firebase, $firebaseAuth, FIREBASE_URL) {
var authData = {};
function authDataCallback(authData) {
if (authData) {
var ref = new Firebase(FIREBASE_URL + "/userProfiles/" + authData.uid);
ref.on("value", function(snapshot) {
var data = snapshot.val();
console.log(data.name);
});
} else {
console.log("User is logged out");
}
}
// Register the callback to be fired every time auth state changes
var ref = new Firebase(FIREBASE_URL);
ref.onAuth(authDataCallback);
return {
authData
};
});
控制器
angular.module('....')
.controller('MainProfileController', function($scope, $firebaseArray, $ionicPopup, FIREBASE_URL, ProfilePics, UserDataService) {
$scope.auth = UserDataService;
console.log(UserDataService);
});