I am new to angualrjs , I am using jQuery DataTable directive with angularJS which is working fine. The problem I am facing is adding javascript function to "TR" dynamically with "ng-click" which is not working. It seem's like dynamically added elements are not recognized by angular.
Can somebody help me out solving this problem.
There are many questions in Stackoverflow and mentioned solution I already tried but not working actually I am using row.add method of jquery for popluating rows.
Please find the code which I am using
angular.module('myApp', [])
.controller('myCtrl', ['$scope','$filter','$http', '$compile', function($scope, $filter, $http,$compile) {
$scope.myFunc = function() {
$http.get('http://localhost:9999/Angular_web/rest/main_search/byaufnum/').
then(function(response) {
var mytable = $('#table1').DataTable();
response.data.map(function(item) {
mytable.row.add(['<span style=\'white-space: nowrap\'><a href=javascript:angular.noop(); ng-click=\"getBGPdata(\''+item.auftragsNr+'\')\">'+item.auftragsNr+'</a></span>']);
$compile(mytable.row)($scope);
})
mytable.draw(false);
});
};
$scope.getBGPdata = function(searchValue) {
console.log('--> '+searchValue);
};
}]);
I know that that problem can be resolved by using $compile and $scope
but not sure how to add this in above code.
Below is the HTML of redering table
<tr role="row" class="odd"><td class="sorting_1"><span style="white-space: nowrap"><a href="javascript:angular.noop();" ng-click="getBGPdata('KRT-ZDK-PMN_NEU-WWT_loopback_SFV_1')">KRT-ZDK-PMN_NEU-WWT_loopback_SFV_1</a></span></td>
$compile(mytable)($scope);
to aftermytable.draw(false);
– Ja9ad335h Feb 22 '17 at 19:35