我最近做內置離子我的應用程序的搜索是從一個API使用HTTP GET方法如下擴展HTTP GET URL鏈接點擊(離子型2 +角2)
static get parameters() {
return [[Http]];
}
searchRecipes(id) {
var url = 'http://api.yummly.com/v1/api/recipes?_app_id=/////&_app_key=//////&q=' + encodeURI(id);
var response = this.http.get(url).map(res => res.json());
return response;
}
到目前爲止拉我有id
這是他們的用戶輸入。我現在想要添加過濾器我的搜索(配料,美食和過敏),這是通過進一步擴展url與特定的電話,如&allowedAllergy[]
和allowedDiet[]
。
我目前有一個實現的項目列表,例如,每個項目都會設置一個值,然後點擊一個項目將添加到提供的URL中。實現是一樣http://www.yummly.uk/
<div class="diets">
<ul>
<li>Lacto vegetarian</li>
<li>Ovo vegetarian</li>
<li>PaleoPescetarian</li>
<li>Vegan</li>
<li>Vegetarian</li>
</ul>
</div>
<div class="allergies">
<ul>
<li>Dairy-Free</li>
<li>Egg-Free</li>
<li>Gluten-Free</li>
<li>Peanut-Free</li>
<li>Seafood-Free</li>
<li>Sesame-Free</li>
<li>Soy-Free</li>
<li>Sulfite-Free</li>
<li>Tree Nut-Free</li>
<li>Wheat-Free</li>
</ul>
</div>
搜索方法
食譜:任何;
searchRecipeDB(event, key) {
if(event.target.value.length > 2) {
this.apiAuthentication.searchRecipes(event.target.value).subscribe(
data => {
this.recipes = data.matches;
console.log(data);
},
err => {
console.log(err);
},
() => console.log('Recipe Search Complete')
);
}
}
如果任何人都可以給出如何實施這個建議,那將是一種拯救生命!感謝所有
如果你有任何問題,它是如何工作的,明天問我。 –
嘿,非常感謝你!它的工作方式非常好,我在很大程度上做了什麼。然而(你是gunna恨我)我現在有我的搜索和過濾搜索單獨工作,因爲這可以看到我的**搜索方法**代碼在問題中。我試圖將其從'this.apiAuthentication.searchRecipes'更改爲'this.searchRecipes',但它引發了一個錯誤,指出**提供的參數不匹配目標**的任何簽名調用。基本上,id不是一個數字,而必須是用戶在搜索中寫入的值。 – BA1995