[英]How do I load data from the server by default when the input is cleared in angularjs syntax es6?
I'm downloading data from the server. 我正在从服务器下载数据。 I have an input that searches for football clubs.
我有一个搜索足球俱乐部的输入。 Everything is ok.
一切都好。 When typing 'manchester', it will search for 'Manchester Utd' and 'Manchester City'.
输入“ manchester”时,它将搜索“ Manchester Utd”和“ Manchester City”。 When I remove the 'manchester', I want to in the situation when input will be empty that it loaded by default 'london'
当我删除“曼彻斯特”时,我想在输入默认为“伦敦”的情况下输入为空的情况
<input type="search" ng-model="query" ng-
change="$ctrl.callGetClubs(query)" placeholder="filter" />
class ClubsController {
constructor(ClubService) {
'ngInject'
this.ClubService = ClubService;
}
callGetClubs(query) {
this.clubs = null;
this.ClubService.getClubs(query).then(response =>
{
this.clubs = response.data;
console.log(this.clubs);
});
}
}
export default ClubsController;
Expectations: 1.Typing 'manchester' ---> display clubs from manchester 2.Delete 'manchester ---> display default clubs from 'london' 期望:1.键入“曼彻斯特” --->曼彻斯特的俱乐部显示; 2.删除“曼彻斯特--->显示默认的俱乐部”伦敦”。
just add default value to query model to the callGetClubs(); 只需将默认值添加到callGetClubs()即可查询模型;
<input type="search" ng-model="query" ng-
change="$ctrl.callGetClubs(query)" placeholder="filter" />
class ClubsController {
constructor(ClubService) {
'ngInject'
this.ClubService = ClubService;
}
callGetClubs(query) {
if(query.length === 0){
query='london';
}
this.clubs = null;
this.ClubService.getClubs(query).then(response =>
{
this.clubs = response.data;
console.log(this.clubs);
});
}
}
export default ClubsController;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.