如何在Angular2中每两分钟调用一次保存功能?
答案 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();
});
<强>提示:强>
Angular&gt; = 6.0.0使用RxJS 6.0.0 Angular Changelog 6.0.0