2
I’m trying to read the data of a Json file in html using Angularjs, but I’m not getting it.
Follows part of the index.html code:
<div ng-app="app">
<div class="page-header" id="principal" ng-controller="HomeCtrl">
<div class="divpai" style="width:950px; height: 734px; background-color:#F3E10A" align="center">
<table class="tclass">
<tr>
<td style="text-align: center;">
<button id="btf1" ng-repeat="menus in mock(0,4)" class="btf" style="width:416px; height: 79px; background-color:#2E5491">{{response.id}}</button>
</td>
<td style="text-align: center;">
<button id="btf5" ng-repeat="menus in mock(4,8)" class="btf" style="width:416px; height: 79px; background-color:#2E5491">{{response.id}}</button>
</td>
</tr>
</table>
</div>
</div>
</div>
Follow code from JSON:
{
"alexa": {
"#text": "",
"item": {
"@attributes": {
"name": "MenuPrincipal",
"label": "Menu Principal"
},
"#text": "",
"children": {
"#text": "",
"child": [{
"@attributes": {
"id": "mnu1"
}
},
{
"@attributes": {
"id": "mnu2"
}
},
{
"@attributes": {
"id": "mnu3"
}
},
{
"@attributes": {
"id": "mnu4"
}
},
{
"@attributes": {
"id": "mnu5"
}
},
{
"@attributes": {
"id": "mnu6"
}
},
{
"@attributes": {
"id": "mnu7"
}
},
{
"@attributes": {
"id": "mnu8"
}
}
]
}
}
}
}
Finally follow the code of my controller.JS:
var app = angular.module('app', []);
app.controller('HomeCtrl', function($scope, $http) {
$http.get('mock.json').then(function(response) {
$scope.data = response.data;
});
});
I have read some questions but still can not find a solution to the case, and in the documentation I could not find a satisfactory solution no example for a beginner as I solve.
Thank you very much.
– Wesley Brito
@Wesleybrito great! I don’t use much Angular but the syntax is similar to other libraries and gave to help :)
– Sergio