I create a simple example of what I'm about to do:
ons.bootstrap()
.controller('AppController', function($scope) {
$scope.x = 0;
setInterval(function() {
$scope.x = $scope.x + 1;
}, 500)
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/onsen/1.3.15/js/onsenui.min.js"></script>
<ons-page ng-controller="AppController">
<ons-list>
<ons-list-header>Switch</ons-list-header>
<ons-list-item>
<br/>
This value should change every 500 milisecond: {{ x }}
<br/>
</ons-list-item>
<ons-list-item>
<div class="center">
Switch is {{ switch ? 'on' : 'off' }}
</div>
<div class="right">
<ons-switch ng-model="data.switch"></ons-switch>
</div>
</ons-list-item>
</ons-list>
</ons-page>
As a normal angular (with two-way data binding) application any change in controller will result the view update and vise versa. But in combination with OnsenUI view update only happens when one onsen component changes updates the view. is there any way to inform onsen about what happened (need of view Update).
try like this
ons.bootstrap()
.controller('AppController', function($scope) {
$scope.x = 0;
setInterval(function() {
$scope.$evalAsync(function () {
$scope.x = $scope.x + 1;
});
}, 500)
});
Edit:
Or use $interval
as @Pankaj Parkar said like this.before use $interval
you should inject this service in your controller.
$interval(function () {
$scope.x = $scope.x + 1;
}, 500);