user2726041 user2726041 - 1 year ago 66
AngularJS Question

Retrieve json data in Angular controller

I'd like to get a couple of values out of a JSON file in my app controller.

I have a JSON file that looks something like this:

"login": [
"username": "admin",
"password": "admin"
"header": [
"subTitle": "Hello",
"color": "red"

I am attempting to retrieve a value like this:

app.controller('loginCtrl', function($http, $scope) {
data = $http.get('data.json');

However, all I'm getting in the console is
TypeError: Cannot read property 'username' of undefined

Answer Source
data = $http.get('data.json');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download