DotNet-301-ElevenNoteAngular
  • Introduction
  • Part 1: Setup with the Angular CLI
  • Part 2: Building out the Header Component
  • Part 3: Sprucing up the Header Using Material
  • Part 4: Building the Registration Page with Reactive Angular Form
  • Part 5: Routing with Angular Router
  • Part 6: Design Break: Fonts
  • Part 7: Communicating with Web API with Auth Service
  • Part 8: Logging in with a token
  • Part 9: Routing After a Request
  • Part 10: Log In page Challenge
  • Part 11: Building the Note Index page
  • Part 12: Creating Note C.r.u.d. — Create
  • Part 13: Creating Note c.R.u.d. — Read
  • Part 14: Creating Note c.r.U.d. — Update
  • Part 15: Creating Note c.r.u.D. — Delete
  • Part 16: Protecting our views with Guards
Powered by GitBook
On this page
  • Step 1. Note Service
  • Step 2. Setting up the form in the Note Edit Controller
  • Step 3. Creating the HTML for the Note Edit
  • Step 4. Finishing the path in the NoteIndex
  • Step 5. Challenge Make the star clickable!
  • Step 6. Challenge answer

Part 14: Creating Note c.r.U.d. — Update

PreviousPart 13: Creating Note c.R.u.d. — ReadNextPart 15: Creating Note c.r.u.D. — Delete

Last updated 7 years ago

Update! We are there. Let’s create the note-edit component from our Angular CLI.

Type:

ng g c components/note/note-edit --no-spec

The update action always involves two http methods, the getNote() by id, the the put method that changes the value of that note.

Step 1. Note Service

The edit note method will mimic our create note method. We have to pass in the full note to the method so it can save the old and the new changes.

Step 2. Setting up the form in the Note Edit Controller

Here in the component we will combine ideas from our note-create and create a form, and the note-details and grab the note by id through the URL params

Then we will create the createForm() method, and then we will pass in the current values of the things we are changeable, so we can see our content in the fields

Finally, create the onSubmit() method that calls our updateNote() method with the note given.

Step 3. Creating the HTML for the Note Edit

Since we have a form for our edit page, the HTML will look addly like the note-create. Except we will have to include the values that are currently set for the:

  • Note id

  • Note title

  • Note isStarred

  • Note content

We made the NoteId and the Star hidden on the page, and i’ll explain why.

When updating the note we need to include the id because that is a value that should not change. For users not to be able to change it we can hide the field. There are other ways of doing that, but we will go with this for now.

Then with the star, it will be changed on the note index page, but just in case you as the developer want to add the ability to the edit page we added that functionality in.

Step 4. Finishing the path in the NoteIndex

To get to the edit page let’s include the routerLink in the note-index page

Step 5. Challenge Make the star clickable!

The goal of this challenge is to test yourselves on the the ngIf directive. For this challenge you have some practice with this *attribute directive. But some knowledge might be new to you so test yourself!

Take no more than 45 minutes on this challenge but allow yourself to struggle with it for a bit.

Step 6. Challenge answer

Visit the docs about the *ngIf and come up with your own solution.

If you missed the documentation over the asterisk that is prepended on the attribute Directives, read more .

here
here
TODO
halfway
Logo Title Text 1
Logo Title Text 1
Logo Title Text 1
Logo Title Text 1
Logo Title Text 1