K
K
Kusmich2015-11-03 01:47:44
JavaScript
Kusmich, 2015-11-03 01:47:44

How to understand this angular function?

I have a json that comes in and which I insert into a tag. In angular, I use a function: which should remove duplicates from the text. But she doesn't work. I need to know what I'm doing wrong. Below is the angular function, and jsonng-repeat="(key, value) in myObj"

<h3 ng-repeat="(val.chef) in data['date']">Андрей<br>Скок</h3>


$.getJSON("data.json", function(data) {
                    $.each(data['date'], function(key, val) {
                            $('body h2').empty().append(val.dolznost);;
                            $('.topick').empty().append(val.anotation);
                            $('.date_block').empty().append(val.dataRel);
                            $('.left_block').attr('src', val.url);;
              
                var mayObj = val.chef
            $('h3').each(function(i,elem) {
              $(this).append(mayObj)
              console.log(val.chef)
            
                
          
            })
              
              
              
              
              
              
              
                    });                             
        });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-11-03
@Kusmich

If you are already taking on angular, forget about working with the DOM directly. Generally. Under no circumstances should you even try to access the element.
It may be true that you are trying to translate the code from jquery to angular, but then it is not clear why you did not bring JSON, but some js code that parses it.
ng-repeat is an angular primitive for creating elements for each element of a collection (array). He shouldn't delete anything. You have to do all this yourself, with a simple Array.filter. Just in JS. Angular is a UI framework, data processing should remain on your conscience.
Make everything simple in JS. JSON input, output the collection of objects you require. Then output this collection through ngRepeat + bindings.
The whole point of angular is to completely separate the data processing logic (what you filter there and under what conditions) from the presentation of this data. Instead of working directly with the DOM, use databinding.

S
Stopy, 2015-11-03
@Stopy

It seems to me that either you have already approached development incorrectly from the very beginning, mixed angular and jquery, mixed logic and manipulation with dom.
Solve the problem on one thing, it will be easier

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question