For this weekend lab you'll be practicing the modular Angular style we dicussed ealier this week, i.e. separating controllers
, directives
, and main
application logic into different files.
You'll be making a Contacts
application where a contact has the following:
name:string cell:string home:string address:string
You'll be creating a contacts application where you can do the following:
- User can create a contact
- User can view all contacts on page
- User can delete a contact
- User can edit a contact
- User can view contacts sorted by name. See
ng-filter
. - User has a
nav
that allows them to click a letter to get contacts whose name starts with that character.
- Include our
trie.js
in ourapplication.js
add a$scope.contactNames
that is anew Trie
. When you get all of your contacts you should learn eachcontact.name
into the$scope.contactNames
trie. - When a user creates a contact add their name to the
$scope.contactNames
.
- Add an input to your page with
ng-model="searchName"
and useng-change
to call agetSuggestions
function that should console.log$scope.searchName
. - Update you
getSuggestions
function to call$scope.contactName.autoComplete($scope.searchName)
. - Set the results of the
autoComplete
to$scope.searchResults
. - Add a
div
to the application.html.erb tong-repeat
through eachresult in searchResults
. - Add an
ng-click
to each div insearchResults
that runsfindContact
andconsole.log
theresult
that was clicked. - Update your
findContact
method in your application to iterate through the$scope.contacts
to find thecontact
whosename
matches the result. Thenconsole.log
that contact - After you find the
contact
set them to$scope.foundContact
and add adiv
to yourapplication.html.erb
that displays thefoundContact
info. - Use
ng-show
to only displayfoundContact
info if there is afoundContact
.
- Review directives to create directives to help you make your own templates for components from part 3.