1

I'm trying to submit a simple form with input in a modal (popup) written in AngularJs:

myApp.run(function($rootScope, $modal) {

    $rootScope.$on('$stateChangeStart', function(event, toState) {

        if (toState.name == 'statePopup') {

            $modal.open({
                templateUrl : 'popup.html',
                controller : 'AllegatiController',
                backdrop: 'static'
            });

            event.preventDefault();

        } else {

            return;
        }
    })
})

The form html is :

<form>
    <div class="form-group">
        <label>File Name:</label> 
        <input type="text"  ng-model="name"></input>
    </div>
    <button ng-click="save()" class="btn btn-primary">Save</button>

</form>

in my controller.js : the $scope.name came undefined

Updated:

This is my controller:

function myController($scope) {
    console.log("all myController");


     $scope.save = function() {

        var name= $scope.name;
        console.log('name is '+name);


    }
}

Maybe seems that in the run of the model which is defined for all the app missed the $scope parameter ?

What am i missed in my code?

selma
  • 77
  • 2
  • 12

2 Answers2

1

Issue solved by updated my ui-bootsrap version up from 0.12.0

This is a link that helped me:

Link angularJs modal submit form

selma
  • 77
  • 2
  • 12
0

If you have this:

$modal.open({
    templateUrl : 'popup.html',
    controller : 'AllegatiController',
    backdrop: 'static'
});

your controller should be:

myApp.controller('AllegatiController', ['$scope', function ($scope) {
    console.log('all myController');

    $scope.save = function () {
       var name = $scope.name;
       console.log('name is '+name);
    }
}]);
axl-code
  • 2,192
  • 1
  • 14
  • 24
  • yes it's like this but with a different definition , the app can recognize the controller, the issue that when i submit the form in the modal, the value doesn't pass to the controller – selma Sep 13 '17 at 07:28