Populating Correct Data In Angular And Json
I am creating an angular template that will be used to show only one set of logos per page on a wordpress micro site - multiple pages, one logo per page with its variations. The da
Solution 1:
Here is an updated fiddle with the code you need:
http://jsfiddle.net/qpzt5akp/6/
There's some code in there to make it work with jsfiddle, but it should be obvious. Main thing: Don't use ng-repeat. No need here.
Here's your controller:
angular.module('brandApp', [])
.controller('brandingContr', ['$scope', '$http', function($scope, $http) {
$http.get('./js/data.json').then(function(data) {
var logos = JSON.parse(data);
var pgTtl = window.title; // or document.querySelector('title').innerHTML; var matchingLogos = logos.filter(function(it,ix,arr) {
return it.logo_name === pgTtl;
});
if(matchingLogos && matchingLogos.length > 0) {
$scope.logo = matchingLogos[0];
} else {
//handle case for no logo found here.//Maybe a default logo, this would continue Promise//Throwing an error here would reject the current Promise.
}
return$scope.logo; //Continue Promise
});
}]);
Post a Comment for "Populating Correct Data In Angular And Json"