2016-04-01 47 views
0

我想用AngularJS的Bootstrap-Confirmation插件,但我似乎無法讓指令正常工作。我使用的是YouTube視頻thisBootstrap-Confirmation與AngularJS的jQuery插件

類似SO question使用另一個稱爲popConfirm的插件,但它以類似的方式使用。我試圖複製該指令,但這也沒有效果。

我想在點擊按鈕時顯示確認對話框,如果點擊「是」,那麼只有通過了ng-click功能。它使用JQuery的JSFiddle Demo

這裏是我到目前爲止的Plnkr Demo

腳本命令:

  1. 的jquery.js
  2. Angular.js
  3. UI-Bootstrap.js
  4. Bootstrap.css
  5. 自舉,Confirmation.js
  6. 應用.js

主要HTML:

<button class="btn btn-xs btn-primary" pop-confirm ng-click="confirm()">Confirm</button> 

應用指令:

app.directive('popConfirm', function(){ 
    var linker = function(scope, element, attr) { 
     element.confirmation(); 
    }; 

    return { 
     link: linker 
    }; 
}); 

回答

0

看這個內置的jQuery庫 這裏 https://nakupanda.github.io/bootstrap3-dialog/

function confirm() { 
BootstrapDialog.show({ 
    title: 'Confirmation Required', 
    message: 'Are you sure? You are about to delete this file.', 
    size: "SIZE_SMALL", 
    type: "type-danger", 

    buttons: [{ 
     label: 'Yes', 
     cssClass: 'btn-primary btn-sm', 
     action: function(dialogItself){ 
      //your ajax codes here if you have or do any requests here 
      dialogItself.close(); 
     } 
    }, { 
     label: 'No', 
     cssClass: 'btn-default btn-sm', 
     action: function(dialogItself){ 
      dialogItself.close(); 
     } 
    }] 
}); 
} 
+0

我想要使用引導,確認插件si這似乎更優雅。有什麼辦法可以讓它起作用嗎?我提到的另一個SO問題是相似的,並且有一個解決方案。我不喜歡popConfirm,因爲popup/tooltip比我想要的大,否則我會嘗試。 – Dev

+0

http://jsfiddle.net/nprL2pc3/ 檢查一下,它應該解決你的問題。對不起,回覆遲到 – Ash

+0

感謝您的回覆,但我正在嘗試將其製作成指令,以便我可以在AngularJS中使用ti。 – Dev