我正在尝试创建一个与Solr一起使用的faceting小部件。如何向每个新添加的构面项添加ng-click事件。因此,当用户单击列表中的项目时,我可以重新查询solr。
HTML用法:
指令:
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 = '
' + data[i] + " (" + data[i + 1] + ")";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);
}
}
};
});
由于