我有以下代码:
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
为什么?