具有value1或value2的angular http查询参数

时间:2017-09-19 14:14:18

标签: angular http

我是角色的新手,我正在尝试使用内存中的web-api来实现我的目的。

让我们说,您已经创建了一个如下所示的InMemoryDbService:

import { InMemoryDbService } from 'angular-in-memory-web-api';

export class InMemoryDataService implements InMemoryDbService 
{
    createDb() 
    {
        const heroes = 
        [
            { id: 0,  name: 'Zero' },
            { id: 11, name: 'Mr. Nice' },
            { id: 12, name: 'Narco' },
            { id: 13, name: 'Bombasto' },
            { id: 14, name: 'Celeritas' },
            { id: 15, name: 'Magneta' },
            { id: 16, name: 'RubberMan' },
            { id: 17, name: 'Dynama' },
            { id: 18, name: 'Dr IQ' },
            { id: 19, name: 'Magma' },
            { id: 20, name: 'Tornado' }
        ];

        return {heroes};
    }
}

如果您想查询单个英雄,您的代码可能如下所示:

import { Injectable } from '@angular/core';
import { Http }       from '@angular/http';

import { Observable }     from 'rxjs/Observable';
import 'rxjs/add/operator/map';

import { Hero }           from './hero';

@Injectable()
export class HeroSearchService 
{ 
    constructor(private http: Http) {}

    search(term: string): Observable<Hero[]> 
    {
        return this.http
                   .get(`api/heroes/?name=${term}`)
                   .map(response => response.json().data as Hero[]);
    }
}

现在我的问题是:当你想查询几个英雄名字时... &#39;术语&#39;将包含值&#39;零&#39;和“纳尔科&#39; ...

import { Injectable } from '@angular/core';
import { Http }       from '@angular/http';

import { Observable }     from 'rxjs/Observable';
import 'rxjs/add/operator/map';

import { Hero }           from './hero';

@Injectable()
export class HeroSearchService 
{ 
    constructor(private http: Http) {}

    // Argument is of type 'string[]' now instead of a single 'string'
    search(term: string[]): Observable<Hero[]> 
    {
        return this.http [????]
    }
}

你是如何做到这一点的?

0 个答案:

没有答案