我使用 https://github.com/simpulton/angularjs-wizard对于我的项目,它有效,
(我稍微修改了一下,将 var app
替换为 $scope
)
但我需要将变量传递给open
函数:
$scope.open = function (image)
{
$scope.image = image;
var modalInstance = $uibModal.open({
templateUrl: 'wizard.html',
controllerAs: 'modal',
size: 'lg',
controller: 'ModalCtrl',
resolve: {
image: function () {
return image;
}
}
});
modalInstance.result
.then(function (data) {
$scope.closeAlert();
$scope.summary = data;
}, function (reason) {
$scope.reason = reason;
});
};
在 html 中:
ng-click="open(image)"
但是 image
在我的模板中是 undefined
如果我只是模式窗口,它就可以工作,示例来自 https://angular-ui.github.io/bootstrap/#/modal , 但不是这个向导示例
更新:
https://jsfiddle.net/Ginstay/znz64sk3/2/
是的,当我打开模态窗口时ajax就完成了
如果我添加一个断点到return image;
image is there
最佳答案
试试这个
angular.module('plunker', ['ui.bootstrap']);
var ModalDemoCtrl = function ($scope, $modal) {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
test: function () {
return 'test variable';
}
}
});
};
var ModalInstanceCtrl = function ($scope, $modalInstance, test) {
$scope.test = test;
};
关于javascript - AngularJS:将变量传递给模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36215211/