javascript - AngularJS:将变量传递给模态

标签 javascript angularjs

我使用 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/

相关文章:

javascript - AngularJS 作用域变量 Unwatch

AngularJS SVG 线渐变不起作用

javascript - 如何添加带有条件和对象属性的 NG 类

javascript - Date.prototype.newFunction 和 Date.newFunction 的区别?

javascript - 如何使用计时器重定向用户

javascript - for in循环奇怪的行为

javascript - CSS 在整个页面上加载不透明度动画

javascript - 为什么需要在 RxJs 中导入运算符?

angularjs - 如何访问 Angular 1.6/es6 应用程序上的表单对象?

javascript - Angularjs - 设置不带 ng-options 的 select 的默认值