Angular 2 interface for service

后端 未结 2 478
深忆病人
深忆病人 2020-12-18 01:16

I want to develop a search component. Here is the following use case:

  1. This component calls a service with search\'s terms parameters.
  2. The service call
2条回答
  •  天涯浪人
    2020-12-18 01:42

    Yes, you can do it like Sefa Ümit Oray answered above. But as I understand, you are trying to filter two type of object in list and you want to use both. So why you don't write a service that has two difference search methods. Or you can write a method that do search in both types of object.

    As you ask, you can use instance of to check the type of object. Then, use Pipe combine with ngIf to do render what you want.

    https://angular.io/docs/ts/latest/guide/pipes.html https://angular.io/docs/ts/latest/api/common/index/NgIf-directive.html

提交回复
热议问题