I am facing an issue with my controller setup as shown below:
angular
.module('app.core')
.controller('TestController', TestController);
TestController.$inject = ['$timeout', '$interval'];
function TestController($timeout, $interval) {
var vm = this;
vm.formHeight = '0px';
$timeout(function() {
var heightCheck = $interval(function() {
var formHeightNew = document.getElementById('form').offsetHeight;
vm.formHeight = formHeightNew + 'px';
}, 500);
}, 2000);
};
An interval is triggered after a delay of 2000ms (inside the timeout function) and then runs every 500ms. It updates the view model but the changes are not reflected in the HTML. How can I apply these updates?
I have attempted using vm.$apply()
and injecting $scope followed by using $scope.$apply()
, but unfortunately, these methods did not work.
In the HTML, I am simply binding the variable to an ngStyle
attribute like this (where the controllerAs value is set to 'test'):
<div class="form-wrapper" ng-style="{'height': test.formHeight}">
</div>
The initial value bound to '0px' works fine, however, any subsequent updates do not reflect in the view.