Last active
November 13, 2018 20:34
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); | |
}; | |
}]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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