I am building a search application.I am using the highlighter function from Johann Burkard's JavaScript text higlighting jQuery plugin. After an angularJS $Http call all the data is bound. I created a directive to call the Highlighter function.
searchApplication.directive('highlighter', function () {
return {
restrict: 'A',
link: function (scope, element) {
element.highlight(scope.searchText);
}
}
});
here is the controller `searchApplication.controller('searchController', function ($scope, $http, searchService) {
$scope.myObject= {
searchResults: null,
searchText: "",
};
$scope.search = function () {
searchService.doSearch($scope.luceneSearch.searchText).then(
function (data) {
$scope.myObject.searchResults = data;
},
function (data, status, headers, configs) {
$log(status);
});
}
});`
here is the service
searchApplication.factory('searchService', function ($http, $q) {
return {
doSearch: function (_searchText) {
var deferred = $q.defer();
var searchURL = '/Search';
$http({
method: 'POST',
url: searchURL,
params: { searchText: _searchText }
})
.success(function (data, status, headers, configs) {
deferred.resolve(data);
})
.error(function (data, status, headers, configs) {
deferred.reject(data, status, headers, configs);
});
return deferred.promise;
}
}
});
In the html I have the following
<td ng-repeat="col in row.fields" highlighter>
{{col.Value}}
</td>
The directive is not getting the value to be searched, rather it gets {{col.Value}} and hence it is not able to highlight.
What am I doing wrong? How can I get the actual bound values so that I can manipulate it? Is there a better way to do this?
Updated: with controller and service code