This course has been updated! We now recommend you take the Angular 9 Fundamentals course.

Check out a free preview of the full Angular Core course:
The "Saving Form Data" Lesson is part of the full, Angular Core course featured in this preview video. Here's what you'd learn in this lesson:

Lukas makes it possible to save projects into the database.

Get Unlimited Access Now

Transcript from the "Saving Form Data" Lesson

>> Lukas Ruebbelke: Let's build out the rest of the project components. So we've done the form. We're capturing the selected object, binding it to the form using ng-model.
>> Lukas Ruebbelke: We know that we can delete a project. But we haven't set anything up to create a project or update a project.

>> Lukas Ruebbelke: So we'll just flesh these out.
>> Lukas Ruebbelke: And I'm just going to copy this for the sake of time.
>> Lukas Ruebbelke: So we wanna create, obviously create. We're going to send in the entire project,
>> Lukas Ruebbelke: Like so.
>> Lukas Ruebbelke: And typically what I will do,
>> Lukas Ruebbelke: For these, definitely, is we'll go ahead and resetProject.

>> Lukas Ruebbelke: And so this is a fairly straightforward call. This is just going to be update. And when it comes in, getProjects, resetProjects. So there are some ways that you can kind of extract this out, make it a little more sophisticated. But you could have just a reset everything or whatever.

[00:01:38] But for now, we'll just leave this here. And when we call saveProject, what we're going to do is,
>> Lukas Ruebbelke: If there's a, or rather, we'll check if is not null,
>> Lukas Ruebbelke: Then we'll call this updateProject, send that in.
>> Lukas Ruebbelke: createProject.
>> Speaker 2: That's the opposite of what you want, I think.

>> Lukas Ruebbelke: Did I do that? So if it's not null, then the id exists and you wanna update it.
>> Speaker 2: It's checking if the doesn't exist.
>> Lukas Ruebbelke: Did I mess that up?
>> Speaker 2: It would evaluate to true.
>> Lukas Ruebbelke: Yes, so if it does exist, you would wanna call it big so good call.

[00:02:46] Okay, and so now let's just see what happens. TEST PROJECT. TEST, we'll set this to some arbitrary number. Let's say you got super lucky and it was 38%, and they're like you're done, you don't have to do any more than this. Then save here, so notice it went, it refreshed it.

[00:03:10] But in order to make sure this is indeed a real deal, scroll down to the bottom. You can see here, done deal. Now one thing I would say is that typically it's tempting working with JSON Server or whatever to have let's make ids be numbers. That doesn't scale very well.

[00:03:31] So even when you're 1, 2, 3, 4, make them strings for this reason right here. Is that their had all numbers then you got a JSON Server some real data base and you get these strings back. So then from here, we can go and we'll just go hea, add some different stuff.

[00:03:54] Let's set this to we're going the extra mile, save. Now, you'll notice here, and this is what we're gonna talk about in the next module.