Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS ng-click not working for dynamically appended kendo panelbar

I have a kendo-ui panelbar and i am dynamically adding items to it, I dont get the ng-click event for those items.

here is I am fetching items and appending to panelbar.

$http.get("/people").success(function (data) {
    var arr = [];
    if (data.success) {
        $.each(data.result, function (k, v) {
            var item = {
                text: v.name,
                items: [{
                    text: 'email: ' + v.email
                }, {
                    text: '<div><button class="k-button" ng-click="edit()">Edit</button></div>',
                    encoded: false

                }]
            };
            arr.push(item);

        });
        usersPanelBar.append(arr, usersPanelBar.element.children("li:last"));
    }
});

This is my controller

function userController($scope, $http, $location, $cookieStore) {
    $scope.edit = function () {
        alert("Will this work?");
        //not workng
    };
}
like image 387
nish Avatar asked Jan 25 '26 19:01

nish


2 Answers

You need to use $compile service to tie your little added snippet to the scope. You may find an example here - angular, in directive, adding to the template an element with ng model

like image 192
devmiles.com Avatar answered Jan 27 '26 09:01

devmiles.com


How about to add something like this to your usersPanelBar

<div ng-repeat="item in items">
    Email: {{item.email}}
    <div><button ng-click="edit()">Edit</button></div>
</div>

And push all retrieved data in the items array

function(data) {
    if(data.success) {
        $scope.items = data.result;
    }
});

Does it make sense?

like image 34
IgorCh Avatar answered Jan 27 '26 09:01

IgorCh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!