如何在angular2中每2分钟调用一次功能?

时间:2016-03-21 14:16:24

标签: angular ionic2

如何在Angular2中每两分钟调用一次保存功能?

1 个答案:

答案 0 :(得分:70)

rxjs 6

从' rxjs';

导入{interval}
<!DOCTYPE html>
<html>
  <body>
    <script>
      var num1;
      var num2;
      var answer;
      num1 = prompt("Enter a number ");
      num2 = prompt("Enter a number ");
      document.write("You entered " + num1 + " and " + num2);
      document.write("<br>");
      answer = prompt("Enter the sum of " + num1 + " and " + num2);
      document.write("You entered " + answer);
      document.write("<br>");
      num1 = parseInt(num1);
      num2 = parseInt(num2);
      var sum = num1 + num2;
      document.write("The sum is " + sum);
      document.write("<br>");
      if (answer == sum) {
        document.write("That is correct!");
      } else {
        document.write("That is not correct. The correct answer is " + sum);
      }
    </script>
  </body>
</html>

rxjs 5

您可以使用

  interval(2000 * 60).subscribe(x => {
    doSomething();
  });

或只是setInterval()

<强>提示:

Angular&gt; = 6.0.0使用RxJS 6.0.0 Angular Changelog 6.0.0

RxJS v5.x to v6 Update Guide