K
K
KOPC18862014-11-26 17:40:05
Angular
KOPC1886, 2014-11-26 17:40:05

How to properly add elements in Angular?

Hello!
Is it correct to add elements like this

if($('#selected_accessApplication_'+access.originalObject.id).length == 0)
                {
                    $('#selectedAccessApplication').append('<div class='selected'></div>')
                }

Or is it more correct to add something through scope ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2014-11-26
@OneFive

$scope.items = [1,2,3];
$scope.items.push(4);

<div ng-repeat="item in intems">{{item}}</div>
<button ng-click="items.push(5)">add</button>

S
Sergey, 2014-11-26
Protko @Fesor

What you wrote is working with the DOM directly. This is valid if you do it inside a directive, but then you need to select from the element on which the directive is hung and try not to go beyond this very element.
In your case, it would be more correct to use ng-repeat and date binding. Actually, if I understand correctly what you want to do - this is the only way you need to do it, otherwise the meaning of using angular is lost. You have no isolation in the end, work with some strange variables, the logic of the application is associated with the view .... word ... fu

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question