I am new to Javascript and Ionic and I would like to know how to display the name of my user in the app itself.
- I have a connection to Firebase that works fine
Here is the code of js file :
var userId = '-KcntxrTC1eZjrkyycn4'; return firebase.database().ref('/accounts/' + userId).once('value').then(function(snapshot) { var displayName = snapshot.val().name; console.log(displayName); // ... });My html file is controlled by the controller where this code is.
The console log renders "Sebastien" so it works
When I write
{{displayName}}in my html document, nothing shows up.
What am I missing ?
EDIT - ADD CODE
Here is the code of my controller :
.controller('accountController',['$scope', '$firebaseArray', 'CONFIG', '$document', '$state', function($scope, $firebaseArray, CONFIG, $document, $state) {
var userId = '-KcntxrTC1eZjrkyycn4';
return firebase.database().ref('/accounts/' + userId).once('value').then(function(snapshot) {
var displayName = snapshot.val().name;
$scope.displayName = snapshot.val().name;
console.log(displayName);
// ...
});
}])
Here is the code of my HTML document :
<!-- *profile-name / name profile -->
<h3 class="profile-name">{{diplayName}}</h3>
The thing is that I get the name to show up in the console as soon as I log in but when I visit the page that is controlled by the actual controller, it doesn't pick it up. Like it didn't understand that it has to take the data from Firebase.
$scopeobject:$scope.displayName = snapshot.val().name;