0

In my controller.js file I have:

    angular.module('App').controller('AppCtrl', AppCtrl);

    function AddApp(){        
      var vm = this;
      vm.resetForm = resetForm;

      function resetForm(){
        vm.myForm.$setPristine();
      }
    }

    ...

    function openModal(message){

    var errorMessage = message;
    var modalInstance = $modal.open({
        templateUrl: 'url',
        controller: 'AppCtrl',
        controllerAs:   'App',
        resolve: {
            errorMessage: function () {
                return errorMessage;
            }
        }
    });
    }

and in my modal I have

    <div ng-controller="AppCtrl as App">
    <form name=App.myForm>
    ...

when I use this format it tells me that vm.myForm is undefined.

This is the closest thing I've found here, but it still did not work for me Can I access a form in the controller?

4

1 回答 1

0

您可以通过将表单添加到解析中来传递表单:

var modalInstance = $modal.open({
        templateUrl: 'url',
        controller: 'AppCtrl',
        controllerAs:   'App',
        resolve: {
            errorMessage: function () {
                return errorMessage;
            },
            myForm: function() {
                return vm.myForm;
            }
        }
    });

在您的模态控制器中:

angular.module('app').controller('AppCtrl',
    ['$scope', 'errorMessage', 'myForm',
        function ($scope, errorMessage, myForm) {

            console.log(myForm);
    }]
);
于 2016-03-09T21:38:20.167 回答