Тільки показувати
0:01
S… Speaker 2 (226. Updating existing Items)
In the last lecture,
0:02
S… Speaker 2 (226. Updating existing Items)
we finished our setup,
0:04
S… Speaker 2 (226. Updating existing Items)
which allowed us to load an item.
0:05
S… Speaker 2 (226. Updating existing Items)
Now I want to make sure that if we are in the edit mode,
0:09
S… Speaker 2 (226. Updating existing Items)
we actually don't add a new one,
0:12
S… Speaker 2 (226. Updating existing Items)
but update the existing one.
0:13
S… Speaker 2 (226. Updating existing Items)
It starts in the template with the button name.
0:16
S… Speaker 1 (226. Updating existing Items)
Here,
0:17
S… Speaker 2 (226. Updating existing Items)
this won't be add at all times.
0:20
S… Speaker 1 (226. Updating existing Items)
Instead,
0:21
S… Speaker 2 (226. Updating existing Items)
this will only be add if we,
0:24
S… Speaker 2 (226. Updating existing Items)
well, are indeed adding an item.
0:27
S… Speaker 1 (226. Updating existing Items)
Otherwise,
0:27
S… Speaker 2 (226. Updating existing Items)
it will be safe.
0:28
S… Speaker 2 (226. Updating existing Items)
So here we can check if edit mode.
0:31
S… Speaker 2 (226. Updating existing Items)
And if this is true,
0:33
S… Speaker 2 (226. Updating existing Items)
and I'm using a ternary expression here,
0:35
S… Speaker 2 (226. Updating existing Items)
I want to output update maybe.
0:39
S… Speaker 2 (226. Updating existing Items)
Otherwise,
0:40
S… Speaker 2 (226. Updating existing Items)
if we are not in edit mode,
0:41
S… Speaker 2 (226. Updating existing Items)
so if we are creating a new item,
0:43
S… Speaker 2 (226. Updating existing Items)
I will save add.
0:44
S… Speaker 2 (226. Updating existing Items)
And now with that,
0:47
S… Speaker 2 (226. Updating existing Items)
we see add as the default,
0:48
S… Speaker 2 (226. Updating existing Items)
but if I click an item here,
0:49
S… Speaker 2 (226. Updating existing Items)
this switches to update.
0:52
S… Speaker 2 (226. Updating existing Items)
Now with that,
0:53
S… Speaker 2 (226. Updating existing Items)
of course, I also want to change the way we save this.
0:56
S… Speaker 2 (226. Updating existing Items)
So in on add item,
0:58
S… Speaker 2 (226. Updating existing Items)
right now we always call add ingredient.
1:01
S… Speaker 2 (226. Updating existing Items)
Now that's not correct if we want to update an existing one.
1:04
S… Speaker 1 (226. Updating existing Items)
First of all,
1:06
S… Speaker 2 (226. Updating existing Items)
in the shopping list service,
1:07
S… Speaker 2 (226. Updating existing Items)
I'll add a new method,
1:09
S… Speaker 2 (226. Updating existing Items)
which I'll name update ingredient.
1:11
S… Speaker 2 (226. Updating existing Items)
Update ingredient.
1:13
S… Speaker 2 (226. Updating existing Items)
And here I expect to get the index of the ingredient which
1:17
S… Speaker 2 (226. Updating existing Items)
should be updated and the new ingredient of type ingredient.
1:22
S… Speaker 2 (226. Updating existing Items)
And with that information,
1:24
S… Speaker 2 (226. Updating existing Items)
I can simply reach out to my ingredients,
1:26
S… Speaker 2 (226. Updating existing Items)
get the one with the index I'm looking for,
1:30
S… Speaker 2 (226. Updating existing Items)
and set it equal to the new ingredient.
1:32
S… Speaker 2 (226. Updating existing Items)
And thereafter,
1:34
S… Speaker 2 (226. Updating existing Items)
I want to call ingredients changed and emit my
1:38
S… Speaker 2 (226. Updating existing Items)
updated ingredients.
1:39
S… Speaker 2 (226. Updating existing Items)
And as always,
1:40
S… Speaker 2 (226. Updating existing Items)
just a slice of them as we did before.
1:44
S… Speaker 2 (226. Updating existing Items)
So with this,
1:45
S… Speaker 2 (226. Updating existing Items)
I'm now updating the ingredient here.
1:48
S… Speaker 2 (226. Updating existing Items)
We need to call this method in onAddItem if we are in edit
1:52
S… Speaker 1 (226. Updating existing Items)
mode.
1:52
S… Speaker 1 (226. Updating existing Items)
Well,
1:53
S… Speaker 2 (226. Updating existing Items)
nothing easier than that.
1:54
S… Speaker 2 (226. Updating existing Items)
We can simply use an if expression,
1:56
S… Speaker 2 (226. Updating existing Items)
check our mode here.
1:58
S… Speaker 2 (226. Updating existing Items)
So if,
1:58
S… Speaker 2 (226. Updating existing Items)
whoops, not that,
1:59
S… Speaker 2 (226. Updating existing Items)
if edit mode,
2:01
S… Speaker 2 (226. Updating existing Items)
if edit mode is true,
2:04
S… Speaker 1 (226. Updating existing Items)
well,
2:05
S… Speaker 2 (226. Updating existing Items)
then I don't want to add a new ingredient.
2:07
S… Speaker 2 (226. Updating existing Items)
Then I want to reach out to the shopping list service and call
2:11
S… Speaker 2 (226. Updating existing Items)
update ingredient.
2:13
S… Speaker 2 (226. Updating existing Items)
And here I will pass my edited item index and
2:17
S… Speaker 2 (226. Updating existing Items)
my new ingredient.
2:18
S… Speaker 1 (226. Updating existing Items)
Otherwise,
2:20
S… Speaker 2 (226. Updating existing Items)
then in this case here,
2:23
S… Speaker 2 (226. Updating existing Items)
I will call add ingredient.
2:26
S… Speaker 2 (226. Updating existing Items)
So now if we save this,
2:28
S… Speaker 2 (226. Updating existing Items)
we should see that indeed,
2:30
S… Speaker 2 (226. Updating existing Items)
if I change this to 10 here or 19 because I mistyped and
2:35
S… Speaker 2 (226. Updating existing Items)
I click update,
2:35
S… Speaker 2 (226. Updating existing Items)
it does update here.
2:37
S… Speaker 2 (226. Updating existing Items)
And the same for tomatoes.
2:39
S… Speaker 2 (226. Updating existing Items)
It updates here.
2:41
S… Speaker 2 (226. Updating existing Items)
Of course, also if I rename this to bread.
2:44
S… Speaker 2 (226. Updating existing Items)
So that's working.
2:45
S… Speaker 2 (226. Updating existing Items)
That is awesome.
2:47
S… Speaker 1 (226. Updating existing Items)
Now,
2:48
S… Speaker 2 (226. Updating existing Items)
let's see if it also works if you create a new item,
2:51
S… Speaker 2 (226. Updating existing Items)
bread.
2:53
S… Speaker 2 (226. Updating existing Items)
Now it correctly adds a new one.
2:55
S… Speaker 2 (226. Updating existing Items)
And if we now click on this,
2:57
S… Speaker 2 (226. Updating existing Items)
we do indeed edit it.
2:59
S… Speaker 2 (226. Updating existing Items)
So this works fine.
3:00
S… Speaker 1 (226. Updating existing Items)
However,
3:00
S… Speaker 2 (226. Updating existing Items)
now I also want to reset the form after updating or
3:05
S… Speaker 2 (226. Updating existing Items)
creating an item.
3:06
S… Speaker 2 (226. Updating existing Items)
And I also want to make this clear button work as well as the delete button.
3:09
S… Speaker 2 (226. Updating existing Items)
Let's start with resetting the form though in the next lecture.

Цей трансляційний документ було створено ШІ (автоматичне розпізнавання мови). Може міститися печки } перевірки на оригінальний аудіо для критичного використання. Правила комп' ютерного гравця

❤️ Любите STT.ai? Розкажіть друзям!
Зведення
Натисніть Summarize, щоб створити резюме AI з цього запису.
Сума...
Запитати комп' ютерного гравця про цей маршрутний індекс
Спитайте що-небудь про цей трансляція ⇩AI знайде відповідні частини і відповідь.