在 Ionic3 中,我设置了一个刷新数据的间隔,我希望它在离开视图时停止。但我无法确定间隔实例的范围...请注意,这是我打字稿的第一步...
updateData(){
var interval = setInterval(() => {
this.getdata.getData().subscribe( data => {
this.channels = data.channels;
})
},2000);
}
ionViewWillLeave() {
clearInterval(interval);//[TS]Cannot find name 'interval'
console.log('leave view');
}
Run Code Online (Sandbox Code Playgroud) 我是离子,html,角度和java脚本的真正新手.我有一个应用程序,它采用一些JSON数据并显示它ng-repeat
.
但是当我试图切换到下一张幻灯片时,它会重叠.我有一个$ interval,每5秒刷新一次JSON,它也重置为第一张幻灯片.
这里的HTML:
<ion-view title="home">
<ion-content ng-controller="temperatureCtrl">
<div ng-init="init()"></div>
<ion-slides options="options" slider="data.slider" >
<ion-slide-page ng-repeat="channel in channels">
<div class="list">
<h2><center>canal# {{channel.canal}}</center></h2>
<br/>
<center>
<button class="button button-stable" ng-click="switchChannel(channel, channel.canal)" ng-model="channel.status">
{{channel.status}}
</button>
</center>
<div class="list">
<label class="item item-input">
<input type="text" style="text-align:center;" placeholder="Channel name" ng-model="channel.name" ng-focus="stopRefresh()" ng-blur="restartRefresh()">
</label>
</div>
<h4><center>
<span class="Ainput" ><h3>{{channel.temperature}}ºC</h3></span>
</center></h4>
<h3><center>Setpoint= {{channel.setPoint}}</center></h3><br>
<div class="item range range-positive">
<i class="icon ion-minus-round"></i>
<input type="range" name="setpoint" min="5" max="30" step="0.5" value="33" ng-model="channel.setPoint" ng-focus="stopRefresh()" ng-blur="restartRefresh()">
<i class="icon ion-plus-round"></i>
</div>
<centrer>
<button …
Run Code Online (Sandbox Code Playgroud)