Skip to content

Instantly share code, notes, and snippets.

@zaidaldabbagh
Last active November 13, 2018 20:34
Show Gist options
  • Save zaidaldabbagh/530d8ff6da02cab400cf1ad322e927b2 to your computer and use it in GitHub Desktop.
Save zaidaldabbagh/530d8ff6da02cab400cf1ad322e927b2 to your computer and use it in GitHub Desktop.
AngularJS Load App Data from JSON — See zaidaldabbagh.com/blog/loading-app-data-from-json-in-angularjs
{
"banner": {
"image": {
"source": "ClientApp/dist/images/nz-fern.jpg"
},
"content": {
"color": "#ffffff",
"heading": "MPI Animal & Plant Import Permits",
"title": "Growing and protecting New Zealand",
"subtitle": "A permit is required to import live animals and plants, and specifie d animal products and plant products. A permit is also required for animals transiting through New Zealand. The requirement for a permit is included in the import health standard for that commodity.",
"action": {
"color": "#333333",
"backgroundColor": "#ffffff",
"link": "https://www.mpi.govt.nz/importing/live-animals/pets/steps-to-importing-cats-and-dogs/",
"linkText": "Learn more"
}
}
}
}
app.controller('homeController', ['$scope', 'appData', function ($scope, appData) {
$scope.appData = {};
$scope.Init = function (data) {
// load app data
appData.getAppData.then(function (appData) {
if (appData) {
$scope.appData = appData;
}
});
};
}]);
/**
* appData
* =======
* Loads app data into scope, including component titles, text, etc.
*/
app.factory('appData', function($http) {
var getAppDataPromise = $http.get('data/components.json').then(function(response){
return response.data;
});
return {
getAppData: getAppDataPromise
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment