Skip to content

Commit 863a6ad

Browse files
committed
Serivico para consumir los json
Agregado el servicio $http de angularjs para traer los json al modelo de la pp
1 parent 0387637 commit 863a6ad

File tree

5 files changed

+52
-28
lines changed

5 files changed

+52
-28
lines changed

app/data/contactos.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"nombre": "Axel",
4+
"apellido": "Salmeron",
5+
"contacto": "@axulsr",
6+
"icon": "<span class='glyphicon glyphicon-user'></span>",
7+
"thumb": ""
8+
},
9+
{
10+
"nombre": "Guillermo",
11+
"apellido": "Seminario",
12+
"contacto": "@gjseminario",
13+
"icon": "<span class='glyphicon glyphicon-user'></span>",
14+
"thumb": ""
15+
},
16+
{
17+
"nombre": "Alexander",
18+
"apellido": "Rondón",
19+
"contacto": "@arondn2",
20+
"icon": "<span class='glyphicon glyphicon-user'></span>",
21+
"thumb": ""
22+
},
23+
{
24+
"nombre": "José",
25+
"apellido": "Salazar",
26+
"contacto": "@jslzrt",
27+
"icon": "<span class='glyphicon glyphicon-user'></span>",
28+
"thumb": ""
29+
},
30+
{
31+
"nombre": "Marlys",
32+
"apellido": "Villafranca",
33+
"contacto": "@MarlysitaV",
34+
"icon": "<span class='glyphicon glyphicon-user'></span>",
35+
"thumb": ""
36+
},
37+
{
38+
"nombre": "Katrina",
39+
"apellido": "Ortiz",
40+
"contacto": "@KatrinaOrtiz",
41+
"icon": "<span class='glyphicon glyphicon-user'></span>",
42+
"thumb": ""
43+
}
44+
]

app/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ <h2>{{globales.seccionActual}}</h2>
4141
<script src="bower_components/angular/angular.min.js"></script>
4242
<script src="bower_components/angular-route/angular-route.js"></script>
4343
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
44+
<script src="bower_components/angular-resource/angular-resource.js"></script>
4445
<script src="scripts/app.js"></script>
4546
<script src="scripts/controladores.js"></script>
4647
</body>

app/scripts/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var app = angular.module('angularFromScratch', [
33
'ngRoute',
44
'ngSanitize',
5+
'ngResource',
56
'app.controladores'
67
])
78
.config(['$routeProvider', function($routeProvider) {

app/scripts/controladores.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,13 @@ angular.module('app.controladores', [])
33
.controller('PrincipalCtrl',['$scope',function($scope){
44

55
}])
6-
.controller('ContactosCtrl',['$scope','$rootScope',function($scope,$rootScope){
6+
.controller('ContactosCtrl',['$scope','$rootScope','$http',function($scope,$rootScope,$http){
77
this.perfilActivo = -1;
88
$rootScope.globales.seccionActual = 'Contactos';
9-
this.contactosArray = [
10-
{nombre: 'Axel', apellido: 'Salmeron', contacto: '@axulsr',
11-
icon: '<span class="glyphicon glyphicon-user"></span>',
12-
thumb:''},
139

14-
15-
{nombre: 'Guillermo', apellido: 'Seminario', contacto: '@gjseminario',
16-
icon: '<span class="glyphicon glyphicon-user"></span>',
17-
thumb:''},
18-
19-
{nombre: 'Alexander', apellido: 'Rondón', contacto: '@arondn2',
20-
icon: '<span class="glyphicon glyphicon-user"></span>',
21-
thumb:''},
22-
23-
{nombre: 'José', apellido: 'Salazar', contacto: '@jslzrt',
24-
icon: '<span class="glyphicon glyphicon-user"></span>',
25-
thumb:''},
26-
27-
{nombre: 'Marlys', apellido: 'Villafranca', contacto: '@MarlysitaV',
28-
icon: '<span class="glyphicon glyphicon-user"></span>',
29-
thumb:''},
30-
31-
{nombre: 'Katrina', apellido: 'Ortiz', contacto: '@KatrinaOrtiz',
32-
icon: '<span class="glyphicon glyphicon-user"></span>',
33-
thumb:''}
34-
];
10+
$http.get('data/contactos.json').success(function (data) {
11+
$scope.contactosArray = data;
12+
});
3513

3614
this.mostrarPerfil = function(indice){
3715
this.perfilActivo = indice;

app/views/contactos.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</tr>
1414
</thead>
1515
<tbody>
16-
<tr ng-repeat="contacto in contactos.contactosArray | filter:busqueda" class="row" ng-click="contactos.mostrarPerfil($index)">
16+
<tr ng-repeat="contacto in contactosArray | filter:busqueda" class="row" ng-click="contactos.mostrarPerfil($index)">
1717
<td class="col-xs-3" ng-bind-html="contacto.icon"></td>
1818
<td class="col-xs-3">{{contacto.nombre}}</td>
1919
<td class="col-xs-3">{{contacto.apellido}}</td>
@@ -25,7 +25,7 @@
2525
<div class="row">
2626
<div class="col-xs-8">
2727
<h3>Perfil de {{contactos.contactosArray[contactos.perfilActivo].nombre}}</h3>
28-
<span class="img-thumbnail perfil-thumb text-center" ng-bind-html="contactos.contactosArray[contactos.perfilActivo].icon"></span>
28+
<span class="img-thumbnail perfil-thumb text-center" ng-bind-html="contactosArray[contactos.perfilActivo].icon"></span>
2929
</div>
3030
<div class="col-xs-4 text-right">
3131
<h3 ng-click="contactos.mostrarPerfil(-1)" class="btn btn-default">

0 commit comments

Comments
 (0)