routing to a component onkeyup angular

So I am trying to implement routing on a search key up. I have my search component as follow

  <div class="form-group input--compressed">
    <div class="form-group__text text-muted">
      <input id="search" placeholder="Search Object" type="search" (keyup)="search($">

Open in new window

search.component.ts like this..
constructor(private router: Router) { }

  ngOnInit() {

search(id: string) {
        this.router.navigate(['/object/' + id]);

Open in new window

my route is defined in app.module.ts
const appRoutes: Routes = [
  { path: 'object/:id', component: ObjectSummaryComponent },
  { path: '', component: DisplayErrorComponent }

Open in new window

If I just type a value in the search box, it doesn't route to my component. But after typing if I press enter does.  I want to be able to route it on after typing ...or if value selected from list of ajax options for search box.  What am I missing here?
Dev MeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dev MeAuthor Commented:
Any help here please?
Dev MeAuthor Commented:
Any update please?
Debasis SahaTeam LeadCommented:

You can use Angular debounce concept using RxJs operator debounceTime() on a form controls value change method like below -

import {Component}   from '@angular/core';
import {FormControl} from '@angular/forms';
import {Observable}  from 'rxjs/Observable';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/throttleTime';
import 'rxjs/add/observable/fromEvent';

  selector: 'my-app',
  template: `<input type=text [value]="firstName" [formControl]="firstName">
export class DemoComponent {
  firstName        = 'Name';
  firstNameControl = new FormControl();
  formCtrlSub: Subscription;
  resizeSub:   Subscription;
  ngOnInit() {
    // debounce keystroke events
    this.formCtrlSub = this.firstNameControl.valueChanges
      .subscribe(newValue => this.firstName = newValue);
      .subscribe(e => {
        console.log('resize event', e);
        this.firstName += '*';  // change something to show it worked

Open in new window

Hope this will help you..
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

Dev MeAuthor Commented:
Not sure if I followed Debasis, my issue is that 'this.router.navigate' doesn't navigate on keyUp.

 this.router.navigate(['/object/' + id]);

Open in new window

Dev MeAuthor Commented:
I haven't received any update for few days despite reporting the question multiple times.
Debasis SahaTeam LeadCommented:
You can use the below code

window.location.replace('/object/' + id);

in place of

Dev MeAuthor Commented:
ok thanks.  So this.router.navigate(['...']) is not valid?
Debasis SahaTeam LeadCommented:
Is this work for you? router.navigate is valid but as per your scenario, it does not work.
Dev MeAuthor Commented:
your solution is working. Want to understand why router.navigate would not work for my scenario.?
Debasis SahaTeam LeadCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.