• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Identifying object ID in JSON by using object property In angular

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm learning angular. I'm working on simple book management app. When user clicks on "Add to favorites, That book will be added to favorites page. Up to now, I have build start page, login page, and register page. I'm using JSON as a database (books.json and users.json) and using JSON-server to host the data. Here my Question is, When the new user is created, How to create Empty Wishlist automatically? And based on Mail id, how to get Id of that object? I have tried some methods in YouTube and documentation. but I was failed.



login-page.component.ts





and here is the code favorite-page.component.ts

 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

So can you show us the code where you register a new user?

On a sidenote, your login code is extremely insecure. Not only are you saving passwords in plain text, when a user tries to log in you are retrieving a password from the server and validating it on the client side. That means that any user can discover the password of any other user just by trying random user names and inspecting the response that comes from the server.
 
Vinay Sayimpu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
register-page.component.ts



Thank you for reply stephan. This is the code to register a new user.
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so your client sends a POST request to the /Users endpoint when it wants to register a new user. So far so good, but you haven't shown us the code that handles the requests to this endpoint.

Please show us the code that handles POST /Users. This is the code that writes the user to JSON, and it's also the code that we need to change if we want to give the new user an empty wishlist.
 
Vinay Sayimpu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your time Stephan. I really appreciate your time and efforts. I actually used https://www.npmjs.com/package/json-server#getting-started this method to host the JSON server. The codes I have mentioned below are the only codes I have used. And also I have achieved this creating the empty wish-list just now. it's very simple. I have just added two empty lists in register-page.component.ts




and whenever I created any new user, It was created automatically.

data.json




The only thing left is I want to export either emailId or ID of the user logged in from the login-page.component.ts to favorite-page.component.ts. Please help me  If you could. Thanks.

Sorry If my English is bad :-)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic