I have a directive that inherits scope from its parent controller. The directive is a div element that overlays the page for three seconds then disappears unless an up/down arrow button is clicked. The div element acts as kind of a modal. This is the code on my DOM
HTML
<div ng-show="volumeVisibility">
<display-volume-modal></display-volume-modal>
</div>
The default setting is false. When volumeVisibility === true, the directive will appear upon a button click. So far, so good. These are my two functions in the controller:
$scope.volumeVisibility = false;
$scope.timer = function(){
console.log("Timer");
$scope.volumeVisibility = false;
};
$scope.displayVolumeModal = function(){
$scope.volumeVisibility = true;
console.log("modal");
};
The timeout works and sets $scope.volumeVisibility === false. However, the div does not remove itself from the page. Here is the code from the directive (I've removed the irrelevant parts):
return {
restrict: 'E',
scope: false,
link: function(scope, elem, attrs){
scope.$watch('volumeVisibility', function(newVal, oldVal){
if (newVal === true){
window.setTimeout(scope.timer, 3000);
document.addEventListener('keydown', function(e){
//stuff
switch (e.which) {
case 38:
//stuff
break;
case 40:
//stuff
break;
}
});
}
}, true);
},
templateUrl: 'public/templates/displayVolumeModal.html'
}
I've tried putting each function into the directive or the controller. What step can I take to make this directive DIV element disappear after timeout?
scope.timerfunction body?ng-showinsidedisplay-volume-modaland get rid ofdiv