I have a form:
<form name="myForm" ng-submit="save(myObject)">
...
<button type="submit" class="btn btn-primary" ng-click="changeLocation('/railway-connection')">Save </button>
</form>
My goal is to perform two actions when the form is submitted. First, to call the save() function and save the data. Second, to change the location.
$scope.save= function (myboject) {
$scope.saveObj = angular.copy(myboject);
console.log($scope.saveObj);
};
$scope.changeLocation(path){
$location.path(path);
};
However, the code is not working as expected. When I click the button, it successfully saves the data and enters the changeLocation() method, but it does not actually change the location.
If I remove the ng-click and instead put $location.path('/next') in the save() function, it works fine. But I prefer to have it within ng-click.
How can I make this work?