F
F
faragly2015-05-04 21:50:41
Angular
faragly, 2015-05-04 21:50:41

How to change link stored in ng-click?

Hello! Tell me, there are rows in the table for multiple addition of elements to the database, when you click on "another field", a new row is dynamically added to the table with fields. So in each line there is a button, ng-click is hung on it to open a new browser window, and a link is written in it. When creating a new table row, you need to change the ng-click value, or rather change the link ... But no matter how you change it, the link opens from the very first row of the table.
Some code:

<button type="button" class="adm-btn" ng-click="jsUtils.openWindow('/element_search.php?lang=ru&amp;id=16&amp;n=news[n0]', 600, 500);">Выбрать</button>

After creating a new line, you need to change the id from the link. How to make the link open CHANGED, and not the one that was the very first one?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
faragly, 2015-05-04
@faragly

I can't forgive myself for this mega-crutch... Is it better?

input.next("button").replaceWith($compile('<button type="button" class="adm-btn" ng-click="'+input.next("button").attr("ng-click")+'"></button>')($scope));

M
Mikhail Osher, 2015-05-04
@miraage

Whoo. Such things should be initially made out by the directive. And depending on the conditions, perform n-th actions.

T
Terminaft, 2015-05-05
@Terminaft

Controller

function tableController() {
    var trArray = []; // [{id: 1, ...}, {id: 2, ...}, ...];
    this.getTrArray = function() { return trArray; }
    this.openWindow = openWindow;

    function openWindow(tr) {
        jsUtils.openWindow('/element_search.php?lang=ru&amp;id=' + tr.id + '&amp;n=news[n0]', 600, 500);
    }
}

Sample
<tr ng-repeat="tr in tableCtrl.getTrArray() track by $index">
    <td>...</td>
    <td><button type="button" class="adm-btn" ng-click="tableCtrl.openWindow(tr)">Выбрать</button></td>
</tr>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question