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);

            });
        }
    };
});

此代码打印 bar,但从不打印 foobarbazz。如果我将调试粘贴到角度引导程序中,它会进入 open 方法,并返回承诺,但从不打开对话框。

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

为什么?

4

1 回答 1

0

我使用jquery.bootstrap.js,它非常小而且简单,与 easyui 类似。

$("#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");
            }
        }
      ]
});
于 2013-10-18T23:59:03.373 回答