How to pass multiple parameters from angular 8 to .NET Core API
just try like this
let headers = new HttpHeaders();
headers = headers.append('responseType', 'json');
return this.http.get<number>(`http://localhost:44353/api/AngularTest/${formattedNumber}/${vin}`, {headers: headers});
and you backend code should be like
[Route("api/[controller]")]
[ApiController]
public class AngularTestController : ControllerBase
{
[HttpGet("{formattedNumber}/{vin}")]
public int CheckIfIDExists(int formattedNumber, string vin)
{
return 0;
}
}
How to pass multiple parameters in http GET request in Angular?
Params can be sent:
const params = new HttpParams()
.set('p1', 'one!')
.set('para2', "two");
and
this.httpClient.get<any>(yoururl,{params}) // {params} short form of {params:params}
Your code looks good, perhaps you have a cors problem: What is StaticSettings.BASE_URL? http or https? Or a relative url?
Passing multiple parameters (objects) from angular to spring/hilbernate
The problem is that you are passing the team2
as a third parameter for the http.put
function, which is taken as options
(not for body
where you need it).
You should send something like that (and I think this will need some more work also on the backend)
function(team, team2) {
return this.http.put('/api/tradeTeam/', {teams: [team, team2]})
.map(res => res.json());
}
See: Angular HTTP Client Docs
How to pass multiple parameters from Angular form to make POST request?
According to your question, if my understanding is correct, You want to pass parameters while making post request.
You can do something like this:
const val = this.form.value;
this.http.post('url', {
first_name: val.first_name,
last_name: val.last_name,
email: val.email,
})
.subscribe(response => {
});
How to send POST in angular5 with multiple params?
The second argument to http.post
is the body of the post request. Just put both values in the body and then get them out of the body on the server.
return this.http.post(this.host+"/saveProjectToClient", {
idPerson,
idProject,
}, {
headers:new HttpHeaders({
'Authorization': this.authService.getToken()
})
});
On the server (Springboot)
public class Dto {
private String idPerson;
private String idProject;
}
@Controller
@RequestMapping("/")
public class ExampleController {
@PostMapping("/saveProjectToClient")
public ResponseEntity postController(@RequestBody Dto dto) {
System.out.print("Person Id was: ");
System.out.println(dto.idPerson);
System.out.print("Project Id was: ");
System.out.println(dto.idProject);
return ResponseEntity.ok(HttpStatus.OK);
}
}
How to pass multiple simple parameters from AngularJS to Web API (using $resource)
Ok here's an example where I passed an object from controller to service, and the service uses $resource
var navApp = angular.module('navApp', [
'ngResource',
'ui.bootstrap',
'ngAnimate'
]);
navApp.controller('menuController', [
'$scope',
'navSectionList',
'navGetCategories',
function ($scope, navSectionList, navGetCategories) {
$scope.navSectionList = navSectionList.query();
$scope.getSectionID = function (event) {
$scope.navGetCategories = navGetCategories
.getResource([event])
.query();
};
}
]);
navApp.factory('navSectionList', [
'$resource',
function ($resource) {
return $resource('/api/navigation/section/list', {}, {
query: { method: 'GET', params: {}, isArray: true }
});
}
]);
navApp.factory('navGetCategories', [
'$resource',
function ($resource) {
var service = {
getResource: function (sectionID) {
return $resource('/api/navigation/category/' + sectionID, {}, {
query: { method: 'GET', params: {}, isArray: true }
});
}
};
return service;
}
]);
getSectionID
kept passing undefined
to navGetCategories.getResource()
until I put event
into a box [event]
.
I still don't really know why it wouldn't work without the square brackets, maybe someone else can explain why.
How to send POST with multiple parameters in AngularJS
Here's what I ended up doing:
The web service is as edited above, allowing the JSON object to be sent to it. The code in the controller is as follows:
vm.sendMail = function (form) {
vm.submitted = true;
vm.msg.message = vm.msg.message.replace(/(\r\n|\n|\r|\n\r)/gm, '<br/>');
var sendMessage = new emailService();
sendMessage.$save(vm.msg)
.then(function () {
vm.sendSuccess = true;
vm.sendFailed = false;
vm.cancel();
})
.catch(function() {
vm.sendSuccess = false;
vm.sendFailed = true;
vm.submitted = false;
});
};
The code in the service is as follows:
(function() {
'use strict';
angular
.module('app')
.service('emailService', ['$resource', emailService]);
function emailService($resource) {
return $resource('/api/email');
};
})();
Thanks for the help, but I really wanted to learn how to do this with the $resource that I'd started out with.
How to pass multiple values to a parameter in a GET API in angular 9+ using http client
You can provide the params like this:
const num = [1,2,3,4]
this.http.get(`/api/request`, {params: {num}});
Related Topics
Calculate Time Difference Between Two Date in Hh:Mm:Ss JavaScript
Input Field Value Should Not Be Greater Than Other Field Value
How to Change Text Value Upon Button Press in React Native
Allow Negative/Positive Numbers But Not Letters
How to Output Date in JavaScript in Iso 8601 Without Milliseconds and With Z
Set State Twice in a Single Function - Reactjs
How to Change Data Due to Selected Value in Select Vue
Close Window Automatically After Printing Dialog Closes
Get a Value from a Observable<Value> Object
How to Hide the Address Bar on Iphone
How Exactly Use and Update the Global Variables in React-Native
Passing Multiple Parameters from Angular to Rest Service
Getting Internal Server Error (500) - Codeigniter
Javascript File Not Updating No Matter What I Do
How to Download Fetch Response in React as File
Prevent a White Space in the Beginning of a Input
How to Reload Datatables from Another Ajax Request With Onclick