I have been struggling to find a solution for my AngularJS issue. As a newcomer to AngularJS, I am not yet familiar with all of its functionalities. I have a multi-part form that is submitted at the end using ng-href and HTTP GET. The code snippet for submission looks like this:
<a ng-href="#/report/{{ctrl.model}}" ng-click="ctrl.createReport()">Finish</a>
Now, I need to add validation to this form and prevent the link from being followed if the validation fails. The validation logic is in a controller function that returns true or false based on the result.
Unfortunately, I am working with code developed by someone else and I want to add validation without making significant changes. Is there a way to conditionally apply ng-href so that the browser follows the URL only if validation passes? If not, is there a way to programmatically perform the same GET request within the controller? I have explored options like $http.get() and $window.location.href, but they do not seem to fit what I need.
If you have any thoughts, ideas, or suggestions, please share them. Thank you!
Solution Used
HTML:
<a data-ng-click="ctrl.createReport()">Finish</a>
JS:
if (validate()) {
$location.path('/report/' + angular.toJson(self.model, false));
}