0

I hope this isn't gonna be too broad.

I have this simple angular website where I show data from firebase (...)

I fetch my data this way in the .js file:

'use strict';

angular.module('webApp.seeHoraire', ['ngRoute', 'firebase'])

.config(['$routeProvider', function($routeProvider){
  $routeProvider.when('/seeHoraire', {
    templateUrl: 'seeHoraire/seeHoraire.html',
    controller: 'SeeHoraireCtrl'
  });
}])

.controller('SeeHoraireCtrl', ['$scope', 'CommonProp', '$firebaseArray', function($scope, CommonProp, $firebaseArray){
  var userId = firebase.auth().currentUser.uid;
  console.log('Current user uid : ', userId);

  return firebase.database().ref('/Users/' + userId + '/Horaire').once('value').then(function(snapshot) {
  var lun1 = (snapshot.val() && snapshot.val().lun1) || 'X';

  $scope.lun1 = lun1;
  console.log($scope.lun1);
  })

}])

This is logging me my "lun1" value perfectly fine, but when it comes to displaying it in my .html file, it shows nothing!

My .html file:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <link rel="stylesheet" href="seeHoraire/seeHoraire.css" />
</head>
<body ng-controller="SeeHoraireCtrl">

  <h1>{{lun1}}</h1>

</body>
</html>

Maybe I forgot something? Please help me. Have a good day.

Chomaunte
  • 15
  • 5

1 Answers1

0

Maybe try:

 $scope.$apply(function(){
    $scope.lun1=lun1;
});

This was copied from: this link. Other answers there may also be helpful.

John Kane
  • 4,383
  • 1
  • 24
  • 42
  • good, it might help other users if you accept this answer then to alert them to this solution. – John Kane Feb 28 '18 at 16:30
  • I tried to do it but then, since I'm new, it says that I need 15 reputations or something like that, sorry.. – Chomaunte Feb 28 '18 at 16:32
  • weird that seems odd... if you can ask a question you should be able to say when it was answered. I can kind of see not being able to vote a question up, but Oh well – John Kane Feb 28 '18 at 16:41
  • 1
    @Chomaunte you need 15 rep in order to upvote but not for [accepting](https://stackoverflow.com/help/someone-answers) the answer. See this too: https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – lealceldeiro Feb 28 '18 at 18:05
  • ohhh I didn't get that you could accept by clicking that check, I thought it was the upward arrow, my bad! – Chomaunte Feb 28 '18 at 21:47