settimeout

Angular4 - how to ensure ngOnDestroy finishes before navigating away

旧街凉风 提交于 2020-08-21 19:42:41
问题 I have a list of objects. The user can click on one, which then loads a child component to edit that component. The problem I have is that when the user goes back to the list component, the child component has to do some cleanup in the ngOnDestroy method - which requires making a call to the server to do a final 'patch' of the object. Sometimes this processing can be a bit slow. Of course what happens is the user arrives back on the list, and that api call completes before the database

How to display each element of an array with different timeout delay and each delay time being a value inside each element in react

萝らか妹 提交于 2020-08-20 12:19:27
问题 Every element of the array should be displayed for some time and the time for which each element is displayed should be determined by a value in each element. let array=[{display:"a",time:10},{display:"b",time:15},{display:"c",time:22}] class App extends React.Component{ state={stateDisplay:"", stateTime:"" } componentWillMount(){ var i=0; let handle=setInterval(()=>{ var element= array[i] this.setState({ stateDisplay:element.display, stateTime:element.time, }) i=i+1; if(i===array.length){

How to display each element of an array with different timeout delay and each delay time being a value inside each element in react

妖精的绣舞 提交于 2020-08-20 12:19:10
问题 Every element of the array should be displayed for some time and the time for which each element is displayed should be determined by a value in each element. let array=[{display:"a",time:10},{display:"b",time:15},{display:"c",time:22}] class App extends React.Component{ state={stateDisplay:"", stateTime:"" } componentWillMount(){ var i=0; let handle=setInterval(()=>{ var element= array[i] this.setState({ stateDisplay:element.display, stateTime:element.time, }) i=i+1; if(i===array.length){

setTimeout and array each

╄→гoц情女王★ 提交于 2020-08-18 09:15:17
问题 I'm confused with using setTimeout and the each iterator. How can I rewrite the following so that the console outputs each name after a delay of 5 seconds? Currently the code below prints all the names at once after 5 seconds. I would like to: 1) wait 5 seconds, then print kevin 2) wait 5 seconds, then print mike 3) wait 5 seconds, then print sally var ary = ['kevin', 'mike', 'sally']; _(ary).each(function(person){ setTimeout(function(){ console.log(person); }, 5000); }); 回答1: You could