Written by

Software Developer at FAMO GmbH & Co. KG
Question Markus Böckmann · Jun 8, 2022

Angular Seachbar with Rest API

Hi guys,

has anyone done a simple angular searchbar with a REST API on Caché in the back?

I've done this Let's write an Angular 1.x app with a Caché REST backend here in the community and it

works fine for me.

The REST in Caché is already developed but im hanging at the searchbar in Angular, don't know how to solve this.

Has somebody an example to help me out?

Any help would be appreciated.

Product version: Caché 2016.1

Comments

DC AI Bot · May 26 Bot

Yes — there is an example in the Angular 1.x + Caché REST series that does exactly this on the Angular side. It adds a text input bound to a scope variable and then uses an ng-repeat filter so the list updates as the user types. [1][2]

The example approach is:

  1. Add a text input at the top of the page.
  2. Bind it to a $scope variable named widgetFilterText.
  3. Wrap the page in a container with layout="column" so the input and cards display vertically.
  4. Feed widgetFilterText into the ng-repeat filter to restrict the displayed data dynamically. [1][2]

The described behavior is that the filtering is done entirely on the client side, so Angular does not need to request filtered data from the server again. The filter applies to all fields of the objects in the list, so it can match values such as ID or Name. [1][2]

If what you need is a simple search bar over data you already loaded from your Caché REST API, this example is the closest match:

  • load the list once from REST,
  • bind the search box to widgetFilterText,
  • use Angular’s filter inside ng-repeat. [3][4][1][2]

There is also a related example showing how to connect Angular 1.x to Caché REST using $http, define an Angular module and controller, and display returned data in the page. It specifically says the controller can use $http to send and consume the results of an HTTP GET, then copy the returned data into a scope variable. [3][4]

If you want a more polished search UI, the series also shows using Angular Material components. It explains that Angular Material must be imported and that 'ngMaterial' must be added as a dependency in the Angular module definition. [5][6]

So for your case, the relevant pieces are:

  • REST call from Angular using $http to fetch the list from Caché, [3][4]
  • a search input bound to widgetFilterText, [1][2]
  • ng-repeat with Angular filtering for instant client-side search. [1][2]

The full series index is available and includes the filtering lesson in Part 5. The code used in the examples is also referenced as being available in the GitHub repository iscChris/CacheRESTStack. [7][8]


Sources:

Tell us more:
Don't like the style
Not factually correct
Didn't fully follow instructions
Refused when it shouldn't have
Being lazy
More...
Submit
0 0