angular ui bootstrap - Submit form in AngularJs Modal -
i'm trying submit simple form input in 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 :
<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 controller.js : $scope.name came undefined
updated:
this controller:
function mycontroller($scope) { console.log("all mycontroller"); $scope.save = function() { var name= $scope.name; console.log('name '+name); } } maybe seems in run of model defined app missed $scope parameter ?
what missed in code?
if 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 '+name); } }]);
Comments
Post a Comment