title: angular 2 and cordova device on ready
body: <p>I have a Cordova app built in angular 2. I have created a custom plugin that goes in to the device retrieves some data then returns this to a page which, all works fine.</p>
  
  <p>However, when this page in question runs at the start of the app opening, the device ready event has not triggered therefore the data is null (as expected) as angular has started before the device is ready. </p>
  
  <p>How can i notify angular 2 that the device ready event has occurred? Usually i would create a Subject and Subscribe.</p>
  
  <p>I'm thinking of doing this in the entry point of the app and use an emit() to notify areas in the app:</p>
  
  <pre><code>document.addEventListener('deviceready', deviceReady());
  </code></pre>
  
  <p>Is there any better options? I know in Angular 1 you would bootsrap the app but it works differently in v2.</p>
  
  <p>UPDATE -----------------------------------------------</p>
  
  <p>I went with the answer from n00dl3 and works great</p>
  
  <p>But used this as my service:</p>
  
  <pre><code>declare var IPFinder, Windows, device;
  @Injectable()
  export class DeviceService {
    // contains the api's for each plugin used
    device: Observable&lt;any&gt;;
  
    constructor(private cordovaService: CordovaService) {
      this.deviceReadyEvent();
    }
  
    // when the device is ready
    deviceReadyEvent() {
      this.device = this.cordovaService.deviceReady.map(() =&gt; {
        console.log('DEVICE READY IN ANGULAR');
  
        // add plugins here
        let deviceAPI = {
          IPFinder: IPFinder,
          device: device
        };
  
        this.platformSpecific(deviceAPI);
  
        return deviceAPI;
  
      });
    }
  
    private platformSpecific(deviceAPI) {
      if (device.platform === 'windows') {
        deviceAPI['Windows'] = Windows;
      }
    }
  
  }
  </code></pre>
  
  <p>Then i call it (requires in constructor private deviceService: DeviceService &amp; zone) using:</p>
  
  <pre><code>   this.deviceService.device.subscribe((device) =&gt; {
  
        device.IPFinder.getIP((ips) =&gt; {
          // zone required to update view
          this.zone.run(() =&gt; {
            this.setIPAddress(ips);
          });
        }, (error) =&gt; {
          console.log('error', error);
        });
      });
  </code></pre>