S
S
Stanislav Botev2017-05-16 14:44:44
Angular
Stanislav Botev, 2017-05-16 14:44:44

How to implement import of arrays from JSON to directives?

Hello.
I recently asked a question . I decided to make a simple application - a list of contacts.
The code is here
Live demo
It would seem that he did what he wanted, but everything is not so simple.
1. It is necessary to call an array of data from JSONs. For each value, for example, lastName , gender etc. there are JSON objects, but I can't connect them correctly.
Example:

[
    {
        "firstname": "Станислав"
    },
    {
        "firstname": "Анатолий"
    },
    {
        "firstname": "Роман"
    },
    {
        "firstname": "Антон"
    },
    {
        "firstname": "Наталья"
    },
    {
        "firstname": "Камиля"
    },
    {
        "firstname": "Валентин"
    },
    {
        "firstname": "Валентина"
    },
    {
        "firstname": "Гульнара"
    },
    {
        "firstname": "Дина"
    },
    {
        "firstname": "Инга"
    },
    {
        "firstname": "Константин"
    }
]

2. Is it possible to set gender to male or female , and then display the corresponding image through validation?
3. How can this application be simplified?
Thank you for your replies, help and support.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2017-05-16
@StasBotev

1. You want to upload data, I understand? To do this, you need to use the $http service .
2. Of course. There are many options, for example, process the data in the controller and add what you need to the genderImage field according to the gender value. You can write 3 directly in the template. At least remove the repeating pieces of code from the template. The table header can be made using ng-repeat, having a list of fields in the controller + a couple of functions for setting the current sorting. Since you are already using Angular 1.5+, make a component instead of a regular controller. Use one-time data bindings, this will reduce the number of watchers. After that, you can try to work with the router, make it possible to go to the page of detailed information about a person by clicking on the table. ng-src={{'/images/' + gender + '.jpg'}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question