简体   繁体   中英

I append to use bootbox.confirm in my directive,but excute wrong

HTML:

<a href="#!uploadstatus"><button type="submit" class="btn btn-primary" confirm-ng-click="Are you sure">Submit</button></a>

angular js is :

omapp.directive("confirmNgClick",function(){
    return {
        priority:-1,
        restrict:'A',
        link: function(scope,element,attrs){
        element.bind('click',function(event){

        var message =  attrs.confirmNgClick || "Are you sure?";
        if (message && !confirm(message)){
             event.stopImmediatePropagation();
             event.preventDefault();
        } //if
        }) // bind
        }//function
    }
})

When I click the button, it raises a confirm box. When I click "yes", the page go to next page. Everything is fine. I want to make confirm box beautiful, so 'm using bootbox.

I have changed the angularjs directive as below :

omapp.directive("confirmNgClick",function(){
    return {
        priority:-1,
        restrict:'A',
        link: function(scope,element,attrs){
        element.bind('click',function(event){
        var message =  attrs.confirmNgClick || "Are you sure?";
        bootbox.confirm(message,function(result){
            if (! result){
                event.stopImmediatePropagation();
                event.preventDefault();
            }

        })

        }) // bind
        }//function
    }
})

It is going wrong. How can I do ?

Thank you in advance.

omapp.directive("confirmNgClick",function(httpPostFactory,$ngBootbox,$location){
    return {
        priority:-1,
        restrict:'A',
        link: function(scope,element,attrs){
        element.bind('click',function(event){
        var message =  attrs.confirmNgClick || "Are you sure?";
        event.stopImmediatePropagation();
        event.preventDefault();
        bootbox.confirm(message,function(result,$location){
            if (result){
                window.location.href = '#!/uploadstatus';
            }
        })
        }) // bind
        }//function
    }
})

The code above is ok

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM