简体   繁体   English

使用angularjs语法es6清除输入后,默认情况下如何从服务器加载数据?

[英]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.

相关问题 如何将函数从服务传递到控制器,并在其中调用Angularjs语法es6? - How do I pass functions from the service to the controller and call it there Angularjs syntax es6? 如何使用 JS ES6 和 jQuery 将特定数据从本地存储加载到新页面? - How do I load specific data from local storage to a new page using JS ES6 and jQuery? 如何根据 React,ES6 中对象数组的搜索输入过滤数据 - How do I filter the data based on search input from array of objects in React, ES6 如何使用angularjs语法es6在两个组件之间传递数据? - How to pass data between two components in angularjs syntax es6? 如何在ES6块中公开数据? - How do I expose data from within ES6 blocks? 从ES5转换为ES6时,如何在React中使用“间隔” - How Do I Use 'interval' With React, When converting From ES5 To ES6 如何将ES6默认参数从子类传递到其超类? - How do I pass ES6 default parameters from a subclass to its superclass? 当我在angularjs中使用ES6语法时,为什么gulp-uglify无法正常工作 - Why gulp-uglify is not working when I used ES6 syntax in angularjs 在ES6中使用扩展语法时使用默认参数? - Use default parameter when using the spread syntax in ES6? 如何在AngularJS中清除输入时调用函数? - How to call a function when input is cleared in AngularJS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM