Sukumar Dhoni Sukumar Dhoni - 1 month ago 10
AngularJS Question

ng-show/ng-hide value is not changing after getting the data from firebase?

when i am receiving the data from the firebase i am changing the scope of the ng-show/ng-hide value with false.but it not affecting any thing in my view.
the scope value is changing when i clicked again but i have to update the value dynamically .
please help me to sought out this problem.

thanks in advance

here is my code



<script>
var app = angular.module("myApp", []);
app.controller("redeemCtrl", function($scope) {
$scope.showDiv = true;
$scope.redeemSubmit = function() {
firebase.database().ref().once('value', function(snapshot) {
$scope.user = snapshot.val()
console.log('Getting Data from fire base' + JSON.stringify($scope.user));
$scope.showDiv = false;
});
}
});
</script>


View



<div ng-controller="redeemCtrl">
<div ng-show="showDiv">
<form>
<div>
<input ng-model="Coupon" type="text">
</div>

<div class="row">
<button ng-click="redeemSubmit()" class="btn">Submit</button>
</div>
</form>
</div>
<div class="row" ng-hide="showDiv">
<h3>{{user}}</h3>
</div>
</div>

Answer

Just notice Angular that a change has made:

   console.log('Getting Data from fire base' + JSON.stringify($scope.user));
   $scope.showDiv = false;
   $scope.user = $scope.Coupon;
   $scope.$apply();
Comments