[英]$modal.open(…) : undefined is not a function
在我的角度控制器中,我想打开一个模态,并检测它何时关闭。 但是文档和我所看到的并不一致。 特别是,当调用'$viewContentLoaded'
上的处理程序时,我从$modal
服务对象中得到了意外的结果。
这是我目前的最佳尝试:
controllersModule.controller('MainCtrl', ['$scope','$log','$location', '$modal',
'$sce', '$q', '$timeout', '$http',
function($scope, $log, $location, $modal, $sce, $q, $timeout, $http) {
$scope.$on('$viewContentLoaded', function checkBrowserCompatibility(){
var m = $modal({title: 'You can read this',
content: 'This works',
show: true,
backdrop: 'static',
keyboard: false});
}]);
以上产生了我期望的模态; 但是, 这建议我应该更称呼它
var m = $modal.open({title: 'You cannot read this',
content: 'This never shows up',
show: true,
backdrop: 'static',
keyboard: false});
这给了我$modal.open(...)
TypeError: undefined is not a function
$modal.open(...)
TypeError: undefined is not a function
我希望能够检测到用户何时关闭模态,尽管这时它不需要任何其他行为不仅如此-不会将数据从模态或类似方式传回。 只需弹出一条消息并继续。
实际上,另一个可接受的(甚至是理想的)行为将阻止模式完全关闭...
我建议这个问题可能是由于Angular js和Angular Bootstrap UI js库不匹配引起的。
请注意,最新版本的AngularJS Bootstrap UI 0.12.1需要Angular 1.2.16+
检查您的包含文件,并且版本兼容。
您想这样称呼它:
var m = $modal.open({
content: 'something',
controller: modalBootstrap,
backdrop: 'static',
keyboard: false,
});
m.result.then(
function () {
//this is called when the modal is closed.
},
function () {
//this is called when the modal is dismissed.
}
);
您将使用controller属性将模态实例传递给模态内部的控制器。 我们称其为引导控制器,如下所示:
var modalBootstrap = function ($scope, $modalInstance) {
$scope.modalInstance = $modalInstance;
};
modalBootstrap['$inject'] = ['$scope', '$modalInstance'];
现在,在模态控制器内部,您可以通过调用以下函数之一来关闭模态:
$scope.modalInstance.dismiss();
$scope.modalInstance.close();
其中的每一个都将关闭模式,并使其触发相应的回调函数。
m.result中的两个函数将被调用,具体取决于模态是关闭还是关闭。 您可以在那里工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.