在我的 angularJS 应用程序中,我试图将参数传递给模态弹出窗口,以便在单击模态链接时,会在弹出窗口中显示一个名称。模态链接来自一个自定义指令,该指令从外部服务获取名称列表。
我已经尝试按照本教程使用 Bootstrap UI 创建 Angularjs 弹出窗口以及$uibModal的文档,因为该教程有点过时了。
我可以让模态 PopUp 和控制器工作,但我不能向它传递参数。
我在Plunker上复制了这个问题。
这个问题是我无法将titlename
参数传递给popupController
fromlistings
指令(请参阅Plunker 中的 script.js)。我认为我的决心设置不正确。在 Chrome 中设置调试器后,我可以看到到目前为止的titlename
值。
app.directive('listings', [function(){
return {
restrict: 'E',
...
controller: ['$scope','$uibModal', function listingsDirectiveController($scope,$uibModal) {
$scope.open = function (titlename) {
var uibModalInstance = $uibModal.open({
templateUrl: 'popup.html',
controller: 'popupController',
titlename: titlename,
resolve: {
item: function(){
return titlename;
}
}
});
}
}]
};
}]);
但它不会传递给popupController
. 在下面的代码中,titlename
具有值undefined
app.controller('popupController', ['$scope','$uibModalInstance', function ($scope,$uibModalInstance, titlename) {
$scope.title1 = titlename;
$scope.close = function () {
$uibModalInstance.dismiss('cancel');
};
}]);
知道为什么会发生这种情况以及如何解决吗?这是resolve
在 AngularJS 中使用的正确方法吗?