2013-07-22 48 views
0

我有下面的代碼:角度引導對話框打開從未

angular.module('myApp').controller('modalClickItemController', function ($scope, $dialog) { 

$scope.openDialog = function(opts){ 
    console.debug('bar'); 
    var d = $dialog.dialog(opts); 
    d.open().then(function(result){ 
     console.debug('foobarbazz'); 
    }); 
} 

}); 

這一個指令用於像這樣:

angular.module('myApp') 
.directive('modalClickItem', function() { 
    return { 
     restrict: 'A', 
     controller: 'modalClickItemController', 
     link: function postLink(scope, el, attr){ 
      scope.objectId = attr.objectId; 
      scope.objectType = attr.objectType 
      scope.opts = { 
       backdrop: true, 
       keyboard: true, 
       backdropClick: true, 
       template: "<div class='modal-header'>Hi!!!</div><div class='modal-body'>Buy!!!</div>", 
    //     templateUrl: 'views/'+scope.objectType+'_modal.html', 
       controller: 'modalCtrl' 
      } 

      el.on('click', function(){ 
       scope.openDialog(scope.opts); 

      }); 
     } 
    }; 
}); 

此代碼打印吧,但是它永遠不會打印foobarbazz。如果我將調試放在角度引導程序中,它將進入開放方法並返回承諾,但不會打開對話框。

http://plnkr.co/edit/tNokVEbRds78tBaVZtLH?p=preview

爲什麼?

+1

據我所知你的「開放式承諾」將在關閉對話框解決:'+ result); } }); 你的modalCtrl在哪裏? – alfrescian

+1

鏈接到jsfiddle請註冊 –

+0

plunkr補充。我的錯 –

回答

0

我使用jquery.bootstrap.js,它非常小巧簡單,與easyui相似。 d.open(),然後(函數(結果){ 如果(結果) { 警報(「對話框,結果收盤:

$("#loginwrap").dialog({ 
     title: "Login" 
    , buttons: [ 
     { 
      text: "Close" 
      , classed: "btn-primary" 
      , click: function() { 
       $(this).dialog("close"); 
      } 
     }, 
     { 
      text: "Login" 
      , classed: "btn-success" 
      , click: function() { 
       //your login handler 

       $(this).dialog("close"); 
      } 
     } 
     ] 
});