12

I'm looking to create a new application based on the Drive Realtime API and want to do it with the shiny new Angular 2 framework. However, I'm kind of stuck trying to figure out how to best integrate the APIs and philosophies. I can't find any examples that use both.

What is the best way to get these two frameworks working together. In particular, how do I reconcile the differences between Angular's two way binding with ngModel and the Realtime APIs data binding with gapi.drive.realtime.databinding.Binding?

Gary
  • 821
  • 8
  • 20

1 Answers1

3

You can download the declaration file (*.d.ts) for the Google Drive Realtime API here. This provides a TypeScript wrapper for the API. Specifically, it defines a module named gapi.drive.realtime whose classes can be accessed in Angular2.

To tell the compiler about the declaration file, you need to add the following line to your TypeScript source file:

///<reference path="google-drive-realtime-api.d.ts" />

Then you need to import the module's features. One way to do this is with the following import command:

import * as Drive from "gapi.drive.realtime";

Then you can access the module's classes under the Drive namespace: Drive.Collaborator, Drive.CollaborativeObject, and so on.

MatthewScarpino
  • 5,672
  • 5
  • 33
  • 47
  • 2
    Thanks for the response. I'm familiar with using type definitions and importing with System.js. Mine is not a simple _'how to use an ES5 library in Typescript?'_ question. My question is more about reconciling the differences between the approaches, such as with data binding. I'm sure I could hack it to get it working, but am looking for thoughts, experience and patterns on how best use a library with collaboration usage constraints in an environment like Angular 2. – Gary Feb 13 '16 at 06:25
  • @MattScarpino do we need to npm install google drive api? – Jek Jan 20 '17 at 01:57
  • @MattScarpino: Where should the reference be added ? I did `npm install' but was not able to understand as to where the reference needs to be added. – Jilna Jun 01 '17 at 12:34