Issue
I was looking here in the site and I couldn’t find anything that would help me.
I have to send parameters to one route, and I have to use form, how do I send the parameters.
the HTML code:
<form ui-sref="root.logiguala" method="get">
Campo:
<input type="text" name="field" ng-model="field">
Valor:
<input type="text" name="values" ng-model="values">
<button type="submit">Carregar</button>
</form>
And this is supposed to comunicate with:
{
name: 'root.logiguala',
url: '/LogIgualA/:field/:values',
params: {
field: { value: null },
values: { value: null }
},
views: {
main: 'home',
},resolve: {
logs: function(pageService,$stateParams) {
return pageService.LogIgualA($stateParams.field,$stateParams.values);
}
},
},
(I really don’t know the correct terminology).
Solution
ui.router
accepts parameters for your states. You probably want to write it as:
<button ui-sref="root.logiguala({'field': field, 'values': values})">Carregar</button>
Or, if you want to use form submission:
<form ng-submit="submit()">
and (in controller)
$scope.submit = function() {
$state.go('root.logiguala', {'field': $scope.field, 'values': $scope.values});
}
(don’t forget to inject $state
into your controller)
Answered By – Aleksey Solovey
Answer Checked By – Robin (AngularFixing Admin)