Answer the question
In order to leave comments, you need to log in
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&id=16&n=news[n0]', 600, 500);">Выбрать</button>
Answer the question
In order to leave comments, you need to log in
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));
Whoo. Such things should be initially made out by the directive. And depending on the conditions, perform n-th actions.
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&id=' + tr.id + '&n=news[n0]', 600, 500);
}
}
<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 questionAsk a Question
731 491 924 answers to any question