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?

Community
  • 1
  • 1

1 Answers1

0

You can pass the form by adding it to the resolve:

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

In your modal controller:

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

            console.log(myForm);
    }]
);
Gene Parcellano
  • 5,799
  • 5
  • 36
  • 43