Reputation: 2735
I am trying to append li element using jquery.the "li" element is appended successfully howerver ng-click event is not working. please help.
below is my code.
$(".language-list").append("<li><span ng-click='selectOperator(op)'><label for=checkbox" + $scope.allOperators[op].operator_id + " class=labeloperator" + ">" + $scope.allOperators[op].operator_name + "</label></div></span></li>");
Upvotes: 0
Views: 367
Reputation: 77904
On append you need compile the element.
It not good practice to do that in controller. Use directive for any DOM selection/manipulation.
Anyways here is example:
var elmnt = angular.element(/* ... */);
elmnt.append(
$compile(
"<li><span ng-click='selectOperator(op)'><label for=checkbox" + $scope.allOperators[op].operator_id + " class=labeloperator" + ">" + $scope.allOperators[op].operator_name + "</label></div></span></li>"
)($scope));
Upvotes: 5
Reputation: 6839
You must compile the dynamic HTML to do the work.
$(".language-list")
.append(
$compile(
"<li><span ng-click='selectOperator(op)'><label for=checkbox" +
$scope.allOperators[op].operator_id + " class=labeloperator" + ">" +
$scope.allOperators[op].operator_name + "</label></div></span></li>")
)($scope);
For more Information about $compile service
Upvotes: 1