JavaScript Use $timeout inside custom AngularJS directive

I want to use $timeout inside my custom AngularJS directive, but it's not working. My last implementation looks as following:

var App = angular.module('App', []);

App.controller('Controller', function($scope){
    $scope.test = true;
    $scope.toggle = function(){ $scope.test = !$scope.test;};
});

App.directive('showTemporary', ['$timeout', function ($timeout) {
    return {
        restrict: 'A',
        link: function(scope, element, attr){
                scope.$watch(attr.showTemporary, function(value){
                element.css('display', value ? '' : 'none');
            });
            $timeout(element.css('display', 'none'), attr.hideDelay);
        }
    }
}]);

And markup:

<div ng-app='App'>
    <div ng-controller='Controller'>
        <button ng-click='toggle()'>toggle</button>
        <div show-temporary='test' hide-delay="5000"> visible</div>
    </div>
</div>
Answer:1

Look carefully at the $timeout docs. The first parameter is FUNCTION, so you probably want it to be like this:

$timeout(function(){
    element.css('display', 'none')
}, attr.hideDelay);
Answer:2

when I am searching any city or state or country in google map then I want the shading of that place as shown in figure. can any one tell me how to do it ?

when I am searching any city or state or country in google map then I want the shading of that place as shown in figure. can any one tell me how to do it ?

I set a span using: <span id=\"xxx\">&#9656;</span> Can someone tell me why the following test doesn't work: if ($("#xxx").text() == "&#9656;") alert("hello");

I set a span using: <span id=\"xxx\">&#9656;</span> Can someone tell me why the following test doesn't work: if ($("#xxx").text() == "&#9656;") alert("hello");

  1. html text special characters

I'm trying to show a hidden listbox in the TinyMCE window. I want to show the listbox after the user selects an option. Currently I have it to show another popup window in the onselect function. Here ...

I'm trying to show a hidden listbox in the TinyMCE window. I want to show the listbox after the user selects an option. Currently I have it to show another popup window in the onselect function. Here ...

I have a simple html form. When the user click on the submit button, a message should pop up to confirm the submission. If the the user click on Ok, the form should be submitted. If the user click on ...

I have a simple html form. When the user click on the submit button, a message should pop up to confirm the submission. If the the user click on Ok, the form should be submitted. If the user click on ...

  1. javascript confirm work
  2. javascript confirm not working
  3. javascript confirm not working in chrome
  4. javascript confirm not working in ie11
  5. javascript confirm not working in safari
  6. javascript confirm not working in firefox
  7. javascript confirm not working in edge
  8. javascript confirm cancel not working
  9. javascript confirm dialog not working in chrome
  10. javascript confirm alert not working
  11. javascript confirm function not working
  12. javascript confirm popup not working
  13. javascript confirm box not working firefox
  14. javascript confirm dialog not working in firefox
  15. javascript confirm dialog not working in ie
  16. javascript confirm dialog not working
  17. javascript confirm return false not working
  18. javascript confirm dialog cancel not working
  19. javascript return confirm not working
  20. javascript confirm cancel button not working