角填充自控制器数据的引导模态形式

时间:2021-12-20 19:37:02

I am trying to populate a modal form with data passed in from my controller. The data being displayed is always NULL, even though I have populated the data in the controller.

我试图用从我的控制器传入的数据填充一个模态表单。显示的数据总是NULL,即使我在控制器中填充了数据。

I have been trying to work this out and have tried a few different ways to do it but none work.

我一直在尝试解决这个问题,并尝试了几种不同的方法来解决这个问题,但都没有成功。

The examples I have seen use $scope, but I don't want to use $scope and instead use controller as

我看到的例子使用了$scope,但我不想使用$scope,而是使用controller作为。

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);

(function () {
    'use strict';

    angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function($uibModal, $log) {

      var vm = this;

        vm.vehicle = [{
            vehicleRegistration: null,
            createUser: null
        }];

        vm.open = function (size) {
            vm.vehicle[0]["vehicleRegistration"] = 'ABCDEFG';
            vm.vehicle[0]["createUser"] = 'BOBF';

            var modalInstance = $uibModal.open({
                templateUrl: 'myModalContent.html',
                controller: 'ModalInstanceCtrl',
                size: 'lg',
                resolve: {
                    items: function () {
                        return vm.vehicle;
                    }
                }
            });
        };
    });
})();


(function () {
    'use strict';

    angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function ($uibModalInstance, items) {
        var vm = this;
        // I want to get the vehicle data pass to populate the form myModalContent.html
        vm.vehicle = items;
    });
})();

Any ideas?

什么好主意吗?

Here is http://plnkr.co/edit/grHKGEJeKqoR8VHOW8I6?p=preview

这里是http://plnkr.co/edit/grHKGEJeKqoR8VHOW8I6?p=preview

1 个解决方案

#1


3  

First, use another name than vm for the modal. I've set it to vm2, also when defining the modal, you have to set the alias for the controller using the word as like this:

首先,对模式使用另一个名称而不是vm。我把它设为vm2,当定义模态时,你必须用这个词来设置控制器的别名:

  var modalInstance = $uibModal.open({
  templateUrl: 'myModalContent.html',
  controller: 'ModalInstanceCtrl as vm2',
  size: 'lg',
  resolve: {
    items: function () {
      return vm.vehicle;
    }
  }
});

Check the link: http://plnkr.co/edit/JmCL6NjAmd2b1UPR8649

检查这个链接:http://plnkr.co/edit/JmCL6NjAmd2b1UPR8649

#1


3  

First, use another name than vm for the modal. I've set it to vm2, also when defining the modal, you have to set the alias for the controller using the word as like this:

首先,对模式使用另一个名称而不是vm。我把它设为vm2,当定义模态时,你必须用这个词来设置控制器的别名:

  var modalInstance = $uibModal.open({
  templateUrl: 'myModalContent.html',
  controller: 'ModalInstanceCtrl as vm2',
  size: 'lg',
  resolve: {
    items: function () {
      return vm.vehicle;
    }
  }
});

Check the link: http://plnkr.co/edit/JmCL6NjAmd2b1UPR8649

检查这个链接:http://plnkr.co/edit/JmCL6NjAmd2b1UPR8649