I'm new to angularJS and still learning. I'm trying to create a navbar in the header which gets the data from ajax call.
However, it shows {{obj.pageData}}
until data is completely received.
It is very annoying to see this everytime I refresh the page!
How could I avoid it to show {{obj.pageData}}
in the view and rather update it directly when the entire data is received from JSON?
Here's the sample code:
View:
<nav ng-app="topNavApp" ng-controller="navCtrl" class="nav">
<div class="nav-center">
<!--<li ng-repeat="obj in pageData.allChildList" ng-model="parentNav" ng-mouseover="parentNav=true" ng-mouseleave="parentNav=false"> -->
<div ng-repeat="obj in pageData.allChildList" class="hiding-div" ng-mouseover="showDiv()" ng-mouseleave="hideDiv()" >
<div>
<a ng-href="{{obj.pagePath}}" class="main-link multiple menu-link">{{obj.pageTitle}}</a>
<!--<span class="main-link mobile" aria-labelledby="{{obj.pageTitle}}" aria-expanded="false">{{obj.pageTitle}}</span>-->
<!--<span ng-repeat="child in obj.secondLevelVoList" class="childNav" ng-show="parentNav">-->
<div class="farm-links" ng-show="hovering">
<!--<a class="prev-link" aria-labelledby="{{obj.pagetitle}}">{{obj.pageTitle}}</a>-->
<div ng-repeat="child in obj.secondLevelChildList" class="groups-links">
<a ng-href="{{child.pagePath}}" class="group-title">{{child.pageTitle}}</a>
<!--<span class="group-title mobile" aria-expanded="false">{{child.pageTitle}}</span>-->
<ul ng-repeat="subchild in child.thirdLevelChildList" class="group-links">
<li class="second-link">
<a ng-href="{{subchild.pagePath}}">{{subchild.pageTitle}}</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</nav>
Controller:
angular.module('topNavApp', []).controller('navCtrl', ['$scope', '$timeout', '$http', function($scope, $timeout, $http){
$http.get("/content/projdata/myJSONData.json").then(function(response){
$scope.pageData = response.data;
})['catch'](function(){
console.log('failed');
});
}]);
Please let me know in case of additional details required.