0

I am trying to implement a function within the controller which will be incharge of showing various notification to the user.

the problem is that I want the duration to be a function parameter, and that doesn't seem to work.

How come?.

How can I fix this?.

    $scope.layout.showNotification = function(msg, duration){
            $scope.layout.notification.message = msg;
            $scope.layout.notification.visible = true;

            if(!duration || duration === null)
                return

            $timeout(function(){
                $scope.layout.notification.visible = false;
                $scope.layout.notification.message = "";
            }, duration);
   }
Oleg Belousov
  • 9,981
  • 14
  • 72
  • 127

1 Answers1

1

Try This

$scope.notification = {
    message : '',
    visible: true
};
$scope.showNotification = function(msg, duration) {
        $scope.notification.message = msg;
        $scope.notification.visible = true;

        if(!duration || duration === null)
            return

        $timeout(function(){
            $scope.notification.visible = false;
            $scope.notification.message = "";
        }, duration);
};

$scope.showNotification('MSH',5000);

DEMO

Nitish Kumar
  • 4,850
  • 3
  • 20
  • 38