Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using contacts


Cordova provides access to the contacts on the user's device through the org.apache.cordova.contacts plugin.

Getting ready

Install the contacts plugin using the following command:

cordova plugin add org.apache.cordova.contacts

Once installed, a contacts object will be added to the navigator, which provides the contacts.create() and contacts.find() methods.

How to do it...

To create a contact, we use the navigator.contacts.create() method. It returns a contact object that can be used by your application. You can pass an object literal to this create() method, which will initialize the various contact properties:

  1. Add the following HTML to index.html:

    <div data-role="view" id="app-contact" 
      data-title="Contacts" 
      data-layout="layout">
      <h3>Contacts</h3>
      <p>
        <a data-role="button" 
          data-click="app.demos.contacts.onAddContact">
          Add Contact</a>
        <a data-role="button" 
          data-click="app.demos.contacts.onFetchContacts"...