O'Reilly logo

Learning Web Development with Bootstrap and AngularJS by Stephen Radford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create

We skipped past the first letter in the CRUD acronym, but now it's time to jump back and hook up our add contact form. The first thing we need to do is ensure our form's inputs all have the relevant model attached:

<input type="text" id="name" class="form-control" ng-model="contact.name">

As we've created a service to handle our contacts, it makes sense that we extend upon this to allow us to create contacts using it as well. Let's make a create method that pushes the contact into the array and add it to our service's object:

create: function(contact){
    contacts.push(contact);
}

We can now think about exactly what we want to happen when we submit our form. We're going to want to insert one contact into our array using the method we just created ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required