Ngx-admin: NbSearchService - question

Created on 1 Nov 2017  路  6Comments  路  Source: akveo/ngx-admin

Hi,

How to use NbSearchService in different components?

reply

Most helpful comment

What I doing wrong? When Nb-search is in diffrent component (HeaderComponent).

export class ListComponent implements OnInit, OnDestroy {
  subscription: Subscription;
  constructor(
    private searchService: NbSearchService) {
  }

  ngOnInit() {
    this.subscription = this.searchService.onSearchSubmit().subscribe((data: { term: string, tag: string }) => this.search() );
  }

  public search() {
  }
  ngOnDestroy() {
    this.subscription.unsubscribe();
  }

}

All 6 comments

Hey @aciechomski, could you elaborate? You can inject it in any component as any other Angular service.

What I doing wrong? When Nb-search is in diffrent component (HeaderComponent).

export class ListComponent implements OnInit, OnDestroy {
  subscription: Subscription;
  constructor(
    private searchService: NbSearchService) {
  }

  ngOnInit() {
    this.subscription = this.searchService.onSearchSubmit().subscribe((data: { term: string, tag: string }) => this.search() );
  }

  public search() {
  }
  ngOnDestroy() {
    this.subscription.unsubscribe();
  }

}

@aciechomski would you mind providing a complete example? What is expected behavior, are there any errors? It's really hard to tell if there are any issues with the code without that info.

Example on ngx-admin.
Component: smart-table.component.ts

constructor(private service: SmartTableService,
  private search: NbSearchService) {
    search.onSearchSubmit().subscribe(data => this.Filter(data.term) )
    const data = this.service.getData();
    this.source.load(data);
  }

  private Filter(text)
  {
    console.log(text);
  }

Why upper search not working?

Pls answer my question.

@aciechomski have you solve the problem?

Was this page helpful?
0 / 5 - 0 ratings