Modify the DOM with ng-click

1

I'm trying to add a link that then has to have a ng-click inside (add or remove certain functionality)

var enlace = '<a class="subEmpleado" ng-click="removeEmployee(user)"><i class="fa fa-minus-square"></i></a>';
var html = $("<p class='employed'>"+user.nombre+" "+user.apellidos+" "+enlace+ "</p>");
$('#anadidos').append(html);
var link_scope = angular.element(html).scope();
compile(html)(link_scope);

The elements are correctly added to the DOM, however it does not enter the function removeEmployeeUser , it seems that angular is not recognizing the element / s that I add dynamically.

I spread the content:

    (function () {
        'use strict';
        var app = angular.module("MyApp", ["ngTable"]);

        app.controller('MyCtrl', function ($scope, $log, NgTableParams) {
            var self = this;
            var data = <?php echo $empleados; ?>;
            self.tableParams = new NgTableParams({count: 10}, {counts: [10, 25, 50, 100], dataset: data});

            $scope.count = 0;
            $scope.addEmployee = function(user){
                $scope.count++;

                var enlace = '<a class="subEmpleado" ng-click="removeEmployee(user)"><i class="fa fa-minus-square"></i></a>';
                var html = $("<p class='employed'>"+user.nombre+" "+user.apellidos+" "+enlace+ "</p>");
                $('#anadidos').append(html);
                var link_scope = angular.element(html).scope();
                compile(html)(link_scope);


                $("#frm_empleados").append("<input type='hidden' name='idempleado[]' value='" + user.idEmpleado + "'/>  ");
            };

            $scope.removeEmployee = function(user){
                //$scope.count--;
                $scope.count = 'user';
            };


        });
    
asked by web developing 17.07.2017 в 14:06
source

1 answer

1

You have to define the $compile service on your controller:

app.controller('MyCtrl', function ($scope, $log, NgTableParams, $compile)

And in the method that generates the html:

$compile(html)(link_scope);
    
answered by 17.07.2017 / 14:54
source