0

I'm working through the AngularJS tutorial, and understand the basics of <li ng-repeat="item in items | filter:query">

However, the out of the box implementation seems limited to just filter the list of items to the exact word or phrase entered in <input ng-model="query">.

Example: if the query is "table cloth", the result list can include a result with this phrase, "Decorative table cloth", but won't include "Decorative cloth for table" because the filter is just a continuous search string.

I know there's the ability to add custom filters, but at first glance it seems like those are mainly transforms.

Is there any way to add a custom filter so that both "Decorative cloth for table" and "Decorative table cloth" show up in the filtered result set?

2 Answers 2

1

Absolutely. Take a look at Angular ng-Route module

You will need to define a route:

$routeProvider.when('/add-item/:itemId', route_descriptor_object)

Here is a plunker with an example: http://plnkr.co/edit/CWq7au244DS1TiuXlu4N

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks very much for both answers!
0

In addition to Vladimir's answer, angular ui router is a commonly used routing library that provides more features than angular's default route provider.

There's a section about passing parameters here https://github.com/angular-ui/ui-router/wiki/URL-Routing#basic-parameters

$stateProvider
  .state('exampleState', {
    url: "/foo/:myParameter",
    templateUrl: 'foo.html',
    controller: function ($stateParams) {
        // If we got here from a url of /foo/42
        expect($stateParams.myParameter).toBe(42);
    }
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.