Reputation: 77
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?
Upvotes: 1
Views: 2870
Reputation: 77
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
Upvotes: 1
Reputation: 2274
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);
}
}]);
Upvotes: 0