angular - Pass parameters through angularjs 2 to restful services -


i trying call webservice follows,

@requestmapping(value = { "/persons" },method = requestmethod.get,headers="accept=application/json") public list<person> getdummydata(@requestparam(value="search", defaultvalue="a") string search,httpservletrequest req){     list<person> listofmatchedpersons=listofpersons.stream().filter(person->person.getname().contains(search)).collect(collectors.tolist());      req.getparametermap().foreach((k,v)->system.out.println(k+" : "+v));      return listofmatchedpersons; } 

i want call service parameter ui, executes method default value of search i.e. a. following angularjs 2's service consuming service,

search(term: string) {      var params = new urlsearchparams();     params.set('search', term);      let aopsservices = 'http://localhost:8080/dummy/persons';//?search='+term;     this.ot = this.http         .get(aopsservices,params)         .map(response => response.json())     ;      return this.ot; } 

however if change url http://localhost:8080/dummy/persons'?search='+term; works.

and should ideal approach access restful services if secured ?

i see 2 ways that:

  • leveraging urlsearchparams class:

    search(term: string) {   var params = new urlsearchparams();   params.set('search', term);    let aopsservices = 'http://localhost:8080/dummy/persons';   this.ot = this.http              .get(aopsservices, { search: params })              .map(response => response.json());    return this.ot; } 
  • use of ` (backticks) instead of single quotes '

    search(term: string) {   let aopsservices = `http://localhost:8080/dummy/persons?search=${term}`;   this.ot = this.http               .get(aopsservices, { search: params })               .map(response => response.json());    return this.ot; } 

    the second approach more concise doesn't urlencode parameter.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -