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);
   }
4
  • Are you sure your duration is an integer ? Maybe you should just parseInt() it ? Commented Sep 17, 2013 at 12:14
  • 1
    Make sure that you have injected $timeout. Commented Sep 17, 2013 at 12:16
  • @LoremIpsum That won't make a difference. Commented Sep 17, 2013 at 12:17
  • What do you mean by 'that doesn't seem to work' ? Do you have an error in the console ? Have you traced the duration value or added a breakpoint ? Commented Sep 17, 2013 at 12:20

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

3 Comments

you can modify now according to your condition
Can you please explain what is the difference between my implementation and yours, because I don't see any difference, thus I cannot use it to solve my problem. Thank for your time and effort
then whats your problem ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.