/* hablo español*/
1-I have this json:
{ "pizarra": [
{
"director": "",
"local": "pizarra",
"telefono": ["2085236", "2085237", "2085238", "2085239", "2085240", "2085241", "2085242"],
"ext": ["0", "211"],
"ubicacion": "lobby",
"puerta": "15202"
}
],
"dirgeneral": [
{
"director": "Blanca Rosa Hung Ramos",
"local": "Secretaria",
"telefono": ["2082546", "2086376"],
"ext": ["258"],
"ubicacion": "Edif. 1 piso 1",
"puerta": "2"
},
{
"director": "Blanca Rosa Hung Ramos",
"local": "Especialista de cuadros",
"telefono": ["2086534"],
"ext": ["270"],
"ubicacion": "Edif. 1 piso 1",
"puerta": "2"
}
]}
...
2-I have this routes:
agendaApp.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/', {
templateUrl: 'src/views/agenda.html', <----see i use the same view
controller: 'pizarraCtrl'
}).
when('/pizarra', {
templateUrl: 'src/views/agenda.html', <----see i use the same view
controller: 'pizarraCtrl'
}).
when('/direccion-general', {
templateUrl: 'src/views/agenda.html', <----see i use the same view
controller: 'dirGrlCtrl'
}).
...
3- i have this service:
agendaServices.factory('getApp',['$resource', function($resource){
return $resource('./data/directorio.json', {}, {
query: {method: 'GET', isArray: false}
});
...
4- i have this controller
agendaControllers.controller('pizarraCtrl', ['$scope', '$rootScope', 'getApp', function ($scope, $rootScope, getApp) {
var data = getApp.query();
$rootScope.datos = data;
console.log(data);
}]);
agendaControllers.controller('dirGrlCtrl', ['$scope', '$rootScope', 'getApp', function ($scope, $rootScope, getApp) {
var data = getApp.query();
$rootScope.datos = data;
console.log(data);
}]);
...
5- i have this partial:
<tr ng-repeat="dir in datos | filter: query | orderBy: orden">
<td style="width: 200px">{{ dir.local }}</td>
<td style="width: 120px">
<select>
<option ng-repeat="phone in dir.telefono">
{{ phone }}
</option>
</select>
</td>
<td style="width: 80px">
<select>
<option ng-repeat="ext in dir.ext">
{{ext }}
</option>
</select>
</td>
<td style="width: 95px">{{ dir.ubicacion }}</td>
<td style="width: 80px;">{{ dir.puerta }}</td>
</tr>
What i need is to use the same view for bind the pizzarra url and the dirgeneral url.
I know to do it with different views putting <tr ng-repeat="dir in datos.pizarra | filter: query | orderBy: orden">
or <tr ng-repeat="dir in datos.dirgeneral | filter: query | orderBy: orden">
but if i try to filter the data in controller lik this: $rootScope.datos = data.pizarra;
it won't bind the data needed.
when i put in my controller a console.log(data); and then looking in my firebug, the data i receive is this: f { $promise={...}, $resolved=false, $get=function(), más...}
why f?
and when i click it:
$promise
Object { then=function(), catch=function(), finally=function()}
$resolved
true
dirgeneral
[Object { director="Blanca Rosa Hung Ramos", local="Secretaria", telefono=[2], más...}, Object { director="Blanca Rosa Hung Ramos", local="Especialista de cuadros", telefono=[1], más...}, Object { director="Blanca Rosa Hung Ramos", local="Auditoria", telefono=[1], más...}, Object { director="Blanca Rosa Hung Ramos", local="Asesor Juridico", telefono=[1], más...}]
pizarra
[Object { local="pizarra", telefono=[7], ext=[2], más...}]
$delete
function()
...