I"m learning something about Angular that I don"t understand about HttpClient.
in-memory-data.service:
const users=[
{id: 1, url: "/assets/home-carousel/1.bmp", like: false, likecount: 0},
{id: 2, url: "/assets/home-carousel/2.png", like: false, likecount: 0},
{id: 3, url: "/assets/home-carousel/3.jpg", like: false, likecount: 0},
{id: 4, url: "/assets/home-carousel/4.png", like: false, likecount: 0},
{id: 5, url: "/assets/home-carousel/5.png", like: false, likecount: 0},
{id: 6, url: "/assets/home-carousel/5.png", like: false, likecount: 0},
{id: 7, url: "/assets/home-carousel/5.png", like: false, likecount: 0},
{id: 8, url: "/assets/home-carousel/5.png", like: false, likecount: 0},
{id: 9, url: "/assets/home-carousel/5.png", like: false, likecount: 0},
{id: 1, username: "admin", password: "admin", email: "email@email.com", birthday: "19970916", exist: "boolean", }
];
return {users};
there is one such data.
I want to return this data only when this.http.get (api/users/?username=admin)
, but now I still return this data even if the request is
this.http.get ("api/users/?username=min")
. So what I want is whether I can achieve the exact search of username
?
found another problem during trial and error. If the request is this.http.get
or other characters, why are json objects that do not have the attribute username returned? it really hurts.
the return value is:
[{"id":1,"url":"/assets/home-carousel/1.bmp","like":false,"likecount":0},{"id":2,"url":"/assets/home-carousel/2.png","like":false,"likecount":0},{"id":3,"url":"/assets/home-carousel/3.jpg","like":false,"likecount":0},{"id":4,"url":"/assets/home-carousel/4.png","like":false,"likecount":0},{"id":5,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":6,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":7,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":8,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":9,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":10,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":11,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":12,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":13,"url":"/assets/home-carousel/5.png","like":false,"likecount":0},{"id":1,"username":"admin","password":"admin","email":"email@email.com","birthday":"19970916","exist":"boolean"}]
I have also read the official api documents. I don"t seem to say that there is such a thing, but I can this.http.get
, but wouldn"t it be necessary to change the structure of the database? Because it seems that he can only match according to the first one? Do you need to get an array starting with username from the background?
another question is that when using http.get
, it is processed from the background, visiting the / user/?username=xxx&id=xxx
of the background, then whether the request is accepted in this place of / user
, and then the following parameters are used as the body of the request?
novice Xiaobai, I hope the bosses can give us an answer! Thank you so much!