I am getting the data in the controller from firebase database using angularfire api and updating the profile.user object from that data.
Now the problem is After login when I am routing to profile.html page, data is not getting pre-filled for that user in the fields which he had saved earlier in the database.
Thank you.
//The controller code is:
.controller('ProfileController', function($rootScope, $timeout, $location, authObj, fbRef) {
var profile = this;
// Check the current user
var user = authObj.$getAuth();
// If no current user send to register page
if (!user) {
$location.path('/register');
return;
}
var userRef = fbRef.child('users').child(user.uid);
(function init() {
// show the message if User moves to profile page
$rootScope.alertInfo = {
title: 'You are successfully logged in!!',
detail: 'You are still logged in',
className: 'alert alert-success'
};
// Load user info
userRef.once('value', function(snap) {
profile.user = snap.val();
if (!profile.user) {
return;
}
});
})();
profile.updateProfile = function() {
userRef.set(profile.user, function onComplete() {
// show the message if write is successful
$rootScope.alertInfo = {
title: 'Successfully saved!',
detail: 'You are still logged in',
className: 'alert alert-success'
};
});
};
})
Corresponding route for this controller is:
.when('/profile', {
controller:'ProfileController as profile',
templateUrl:'view/profile.html'
})
View for this controller is(profile.html):
<form id="frmProfile" role="form">
<h2>Profile</h2>
<br />
<div class="form-group">
<label for="txtName">Name</label>
<input type="text" ng-model="profile.user.name" class="form-control" id="txtName" placeholder="Name" name="name" />
</div>
<div class="form-group">
<label for="ddlDino">Favorite Dinosaur</label>
<select id="ddlDino" ng-model="profile.user.favoriteDinosaur" name="favoriteDinosaur" class="form-control">
<option>None</option>
<option>Pteranodon</option>
<option>Lambeosaurus</option>
<option>Stegosaurus</option>
<option>Daspletosaurus</option>
</select>
</div>
<button type="submit" ng-click="profile.updateProfile(profile.user)" class="btn btn-primary">Update</button>