I have a search box which on the input will get a json data from a server and create a menu list from the json data. so, I've created a funcion in the controller that is triggered when there is a change in the search box through ng-change, also the function calls a different function createMenu which injects the list elements with something like, element.append(''+name+'');
but the handleClick method seems to be never triggered when I click the list item. can anyone tell me how to resolve this? any help will be appreciated. thanks! :)
//ascript.js
var landApp = angular.module('landApp', ['ngRoute']);
function navCtrl($scope , $compile, $element, $rootScope , $http) {
$scope.handleClick = function(id) {
console.log("Clicked");
console.log(id);
};
$scope.createMenu = function(elementJson,element) {
if(angular.isArray(elementJson)) {
angular.forEach(elementJson, function(child , key) {
$scope.createMenu(child,element);
});
return;
}
var name = elementJson.name;
var id = elementJson.id;
var children = elementJson.child;
if(name=="Product"){
$scope.createMenu(children,element);
return;
}
var elem = angular.element('<ul></ul>');
element.append(elem);
$scope.createMenuElement(name,id,elem);
if(children != null || children !=undefined) {
if(angular.isArray(children)){
angular.forEach(children , function(child,key) {
$scope.createMenu(child,elem);
});
} else {
$scope.createMenu(children,elem);
}
}
}
$scope.createMenuElement = function(name,id,element) {
element.append('<li id = '+id+' class = product ng-click = handleClick('+id+') >'+name+'</li>');
}
$scope.search_change = function() {
if($scope.query.length > 0) {
var elem = angular.element('#navigator');
//angular.element('#navigator');
$http.get('/data/search?query=' + $scope.query).
success(function(data, status, headers, config) {
console.log(data);
elem.html('');
var children = data.child;
console.log(children);
$scope.createMenu(children,elem);
}).
error(function(data, status, headers, config) {
// log error
});
};
}
}
}