让@HostListener等待开始之前

时间:2020-02-11 17:53:04

标签: angular

我正在使用@HostListener滚动事件获取角度,我希望找到一种方法,让它等待3秒钟才能执行任何操作,但仅限于第一次触发

out[[1]]
#$glm
# A tibble: 6 x 4
#  Sepal.Width Sepal.Length glm_Model glm_Prediction
#        <dbl>        <dbl> <chr>              <dbl>
#1         2.3         5    glm                    0
#2         2.3         5.01 glm                    0
#3         2.3         5.02 glm                    0
#4         2.3         5.03 glm                    0
#5         2.3         5.03 glm                    0
#6         2.3         5.04 glm                    0

#$svm.formula
# A tibble: 6 x 4
#  Sepal.Width Sepal.Length svm.formula_Model svm.formula_Prediction
#        <dbl>        <dbl> <chr>                              <dbl>
#1         2.3         5    svm.formula                            0
#2         2.3         5.01 svm.formula                            0
#3         2.3         5.02 svm.formula                            0
#4         2.3         5.03 svm.formula                            0
#5         2.3         5.03 svm.formula                            0
#6         2.3         5.04 svm.formula                            0

#$randomForest.formula
# A tibble: 6 x 4
#  Sepal.Width Sepal.Length randomForest.formula_Model randomForest.formula_Prediction
#        <dbl>        <dbl> <chr>                                                <dbl>
#1         2.3         5    randomForest.formula                                     0
#2         2.3         5.01 randomForest.formula                                     0
#3         2.3         5.02 randomForest.formula                                     0
#4         2.3         5.03 randomForest.formula                                     0
#5         2.3         5.03 randomForest.formula                                     0
#6         2.3         5.04 randomForest.formula                                     0

#$xgb.Booster
# A tibble: 6 x 4
#  Sepal.Width Sepal.Length xgb.Booster_Model xgb.Booster_Prediction
#        <dbl>        <dbl> <chr>                              <dbl>
#1         2.3         5    xgb.Booster                        0.388
#2         2.3         5.01 xgb.Booster                        0.388
#3         2.3         5.02 xgb.Booster                        0.388
#4         2.3         5.03 xgb.Booster                        0.388
#5         2.3         5.03 xgb.Booster                        0.388
#6         2.3         5.04 xgb.Booster                        0.388

2 个答案:

答案 0 :(得分:3)

IntStream i = IntStream.of(5,6,7,1,2,3,4);
//IntStream o =  i.sequential();
i.forEach(System.out::println);

...

String day = editTextDay.getText().toString().trim();
    String month = editTextMonth.getText().toString().trim();
    String year = editTextYear.getText().toString().trim();

  //  SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");


    String BirthDate ="" + year + '-' + month + '-' + day;
    LocalDate sDate = new LocalDate(BirthDate);
    LocalDate today = new LocalDate();

    Period period = new Period(sDate, today, PeriodType.yearMonthDay());
    int years = period.getYears();
    int months =period.getMonths();
    int days = period.getDays();

    textViewDay.setText(""+days);
    textViewMonth.setText(""+months);
    textViewYear.setText(""+years);

现在我们可以限制响应等了。

答案 1 :(得分:2)

您可以尝试以下代码段。希望对您有帮助。

 timeOutId:number;
    @HostListener('window:scroll', ['$event']) getScrollHeight(event) { 
    clearTimeout(this.timeOutId);
    this.timeoutId = setTimeout(() => { 
       // call your method 
    }, 3000); 
 }
相关问题