我正在阅读一个chatapp教程,它说当我重定向到http://localhost:4000/#/profile时,我应该能够为我们的用户指定一个显示名称,提交表单,它应该在我们刷新页面时保持不变。问题是,当我去那里时,没有任何东西出现,只是一个白色的屏幕。我错过了半结肠吗?
app.js中的个人资料状态
.state('profile', {
url: '/profile',
controller: 'ProfileCtrl as profileCtrl',
templateUrl: 'Users/profile.html',
resolve: {
auth: function($state, Users, Auth) {
return Auth.$requireAuth().catch(function(){
$state.go('home');
});
},
profile: function(Users, Auth){
return Auth.$requireAuth().then(function(auth){
return Users.getProfile(auth.uid).$loaded();
});
}
}
});
profile.controller.js
angular.module('chatApp')
.controller('ProfileCtrl', function($state, md5, auth, profile){
var profileCtrl = this;
profileCtrl.profile = profile;
profileCtrl.updateProfile = function(){
profileCtrl.profile.emailHash = md5.createHash(auth.password.email);
profileCtrl.profile.$save();
}
});
users.service.js
angular.module('chatApp')
.factory('Users', function($firebaseArray, $firebaseObject, FirebaseUrl){
var usersRef = new Firebase(FirebaseUrl+'users');
var users = firebaseArray(usersRef);
var Users = {
getProfile: function(uid){
return $firebaseObject(usersRef.child(uid));
},
getDisplayName: function(uid){
return users.$getRecord(uid).displayName;
},
getGravatar: function(uid){
return '//www.gravatar.com/avatar/' + users.$getRecord(uid).emailHash;
},
all: users
};
return Users;
});
profile.html
<div class="page-wrapper">
<div class="page-header">
<h1>Edit Profile</h1>
</div>
<form ng-submit="profileCtrl.updateProfile()">
<p ng-hide="profileCtrl.profile.displayName">
You'll need a display name before you can start chatting.
</p>
<div class="input-group">
<input required type="text" class="form-control" placeholder="Display Name" ng-model="profileCtrl.profile.displayName">
</div>
<input type="submit" class="btn btn-default" value="Set Display Name">
</form>
</div>