Error ng-repeat Angularjs

0

I have the following json object

$scope.datos = {
    "status":200,
    "data":{
        "username":"username1",
        "nombre": "Diego",
        "apellido": "Moreno Leon",
        "telefono": "999999",
        "celular": "000009901661",
        "email": "[email protected]",
        "tipo_usuario": 1,
        "empresas": [
            {
                "id_empresa": 1,
                "nombre_emp": "Hotel Libertador",
                "email": "[email protected]",
                "calle_principal": "Av. Eduardo Kingman",
                "calle_secundaria": "Catamayo",
                "barrio": "Los Arupos",
                "numero_casa": "14-14",
                "latitud":"-11212121331",
                "longitud":"2122112122"
            },
            {
                "id_empresa": 2,
                "nombre_emp": "Hotel Loja",
                "email": "[email protected]",
                "calle_principal": "Av. Pio Jaramillo",
                "calle_secundaria": "Meradillo",
                "barrio": "San Sebastian",
                "numero_casa": "60-45",
                "latitud":"-34444444444",
                "longitud":"21111111"
            }
        ],
        "categorias": [
            {
                "id_categoria":1,
                "nombre_cat":"Gastronomia",
                "sitios":[
                    {
                        "id_empresa": 1,
                        "nombre_emp": "Bourbon",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    },
                    {
                        "id_empresa": 2,
                        "nombre_emp": "La Mojigata",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    },
                    {
                        "id_empresa": 3,
                        "nombre_emp": "Obelics",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    }
                ]
            },
            {
                "id_categoria":2,
                "nombre_cat":"Deportes",
                "sitios":[
                    {
                        "id_empresa": 4,
                        "nombre_emp": "Coliseo Loja",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    },
                    {
                        "id_empresa": 5,
                        "nombre_emp": "Coliseo de Machala",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    },
                    {
                        "id_empresa": 6,
                        "nombre_emp": "Coliseo del Oro",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    }
                ]
            },
            {
                "id_categoria":3,
                "nombre_cat":"Transporte",
                "sitios":[
                    {
                        "id_empresa": 7,
                        "nombre_emp": "Sur Oriente",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    }
                ]
            },
            {
                "id_categoria":4,
                "nombre_cat":"Bares",
                "sitios":[
                    {
                        "id_empresa": 8,
                        "nombre_emp": "La Pupila",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    },
                    {
                        "id_empresa": 9,
                        "nombre_emp": "Coyote Bar",
                        "email": "[email protected]",
                        "calle_principal": "Av. Pio Jaramillo",
                        "calle_secundaria": "Meradillo",
                        "barrio": "San Sebastian",
                        "numero_casa": "60-45",
                        "latitud":"-34444444444",
                        "longitud":"21111111"                       
                    }
                ]
            }
        ]
    }
};

and I want to show it in the following way

<ul ng-repeat="i in datos">
    <li>{{$index}}</li>
    <li><input type="button" value="{{i.username}}"></li>
  </ul>

But when I show in my html view I have two buttons with the first empty value and the second with the value of username, what I want to know is how I present only the value of username without repeating the empty values in advance I thank you.

Additional data working with bootstrap and with the angularjs version: 1.5.8

    
asked by Dimoreno 09.05.2017 в 18:57
source

1 answer

1

In the documentation says that to use the ngRepeat directive it is used under the nomenclature:

<li ng-repeat="modelo in coleccion"></li>

where modelo is the name that iterates in coleccion . Being coleccion of type array .

So in your JSON if you only want to show the data, the directive to link the model to the view you can use is ng-bind in the following way:

<span ng-bind="datos.username"></span>

Later on if you want to add functionality with functions you can do:

<button class="btn btn-default" ng-bind="datos.username" ng-click="cambiarNombre( datos.username )"></button>

Notice how I use the ng-click directive to assign a function that is in the scope and I pass it by parameter the username that contains data.

Greetings

    
answered by 09.05.2017 в 19:30