The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Building an Angular App: Editing a bookmark with ng-model and a controller

Building an Angular App: Editing a bookmark with ng-model and a controller

9:13
We are going to learn how to edit an existing bookmark by building on a lot of the same techniques from the previous video. We will also learn how to edit a bookmark and not actually save the change back to the collection until we are ready. Find the code [on Github](https://github.com/eggheadio/egghead-angularjs-from-scratch-getting-started/tree/06-editing-bookmark). Tags correspond to the lesson.
Watch this lesson now
Avatar
egghead.io

We are going to learn how to edit an existing bookmark by building on a lot of the same techniques from the previous video. We will also learn how to edit a bookmark and not actually save the change back to the collection until we are ready.

Find the code on Github. Tags correspond to the lesson.

Avatar
Israel

for some reason my active class didn't work to highlight the bookmark being edited. The div surrounded this code has the main class which in the css seems to be correct.

×

{{bookmark.title}}

CSS:

.main .active span,
.main .active > a {
color: #5bc0de;
}

Avatar
Jay

There is a minor bug with the active class on the bookmark. When you cancel editing, it still shows that the bookmark you were editing is active. The fix is similar to the fix in the create video - set editedBookmark to null when cancelEditing is called.

Avatar
Xavier

I second that, I added setEditedBookmark(null);

In reply to Jay
Avatar
Piyush

Is there an alternative to using Lodash for finding a bookmark in the collection? I'd love to go learn Lodash, but for the moment I want to stay here.

Avatar
Henrique Zavareze

For some reason my underscore function always returns -1. Any thoughts?

'''
var index = _.findIndex($scope.bookmarks, function (b) {
return b.id = bookmark.id;
});
'''

Avatar
Kyle Kerley

Everything in this video is working except for the actual updating of the record. No matter what I do, when I hit "save" on the edit form, the changes are not reflected in the list of bookmarks.

EDIT: Turns out, it's because I was coding this in a simple HTML file without Bootstrap (or using the provided code on Github so I could get a feel for coding it all myself) and therefore missed the part where I had to manually include the lodash library. After that was added, everything worked fine.

Avatar
Sina

using '=' is for assigning values. If you want to compare, you need to use '==' or '==='

In reply to Henrique Zavareze
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?