user3043124
user3043124

Reputation: 488

Creating on-the-fly angularjs variable URL?

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?

Upvotes: 0

Views: 544

Answers (2)

eddiec
eddiec

Reputation: 7646

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);
    }
})

Upvotes: 0

Vlad Gurovich
Vlad Gurovich

Reputation: 8463

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

Upvotes: 1

Related Questions