I am trying to create a faceting widget that works with Solr. How do I add ng-click event to each newly added facet item. So when a user clicks on an item in the list, I can re-query solr.
HTML Usage:
<facet field="query.response.facets.facet_fields.location" name="location" />
Directive:
var commonComponentsApp = commonComponentsApp || angular.module('cpUtils', []);
commonComponentsApp.directive("facet", function($compile) {
'use strict';
return {
restrict: "E",
scope: {
field: "=",
name: "@"
},
link: function (scope, element) {
var list = new Array(), i, facet_item;
scope.$watch('field', function (data) {
if (data === undefined || data === null) {
return;
}
for (i = 0; i <= data.length - 1 ; i += 2) {
facet_item = '<li class="unstyled" ng-click=applyFilter('+ scope.name + "," + data[i] + ')>' + data[i] + " (" + data[i + 1] + ")</li>";
var e = angular.element(facet_item);
$compile(e.contents())(scope);
list.push(e);
}
element.html(list);
});
scope.applyFilter = function (facet, value) {
console.log("called");
console.log(facet + ' ' + value);
}
}
};
});
Thanks