Microsoft is not defined

Hey guys,

Since I updated to ionic RC0 and also RC1, I’m facing this problem with cordova-plugin-ms-adal.

I run:
ionic plugin add cordova-plugin-ms-adal
and also removed and run cordova plugin

Tried with declare var Microsoft: any; before [at]Component but it`s not working at browser even device.

Problem:
Microsoft is not defined

My .ts file:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-page1',
  templateUrl: 'page1.html'
})
export class Page1 {

  constructor(public navCtrl: NavController) {

  }

  login() {
    console.log("MS ADAL");
    let authContext = new Microsoft.ADAL.AuthenticationContext("https://login.microsoftonline.com/common");

    authContext.acquireTokenAsync("https://graph.microsoft.com", "[APP ID]", "http://localhost:8000")
      .then((res) => {
        console.log(res);
      });
  }

}

I’m getting this same error. Has anyone found a solution?

I’m having this issue as well. Has anyone found a fix?

I’ve tried angular2-adal npm package as well but getting Could not resolve 'adal' error.

I SOLVED the problem inserting a platform.ready() check:

My new .ts file is:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { NavController } from 'ionic-angular';

declare var Microsoft: any;

@Component({
  selector: 'page-page1',
  templateUrl: 'page1.html'
})
export class Page1 {

  constructor(public navCtrl: NavController, platform: Platform) {
    console.log("MS ADAL");

    platform.ready().then(() => {
      let authContext = new Microsoft.ADAL.AuthenticationContext("https://login.microsoftonline.com/common");

      authContext.acquireTokenAsync("https://graph.microsoft.com", "[YOUR-APP-ID]", "http://localhost:8000")
        .then((res) => {
          console.log(res);
        });
    });
  }
}

Hey everyone.
I was facing the same issue. But I found a simple solution and, in my opinon, more suitable.

Just install the typings package like this: npm i --save @types/cordova-plugin-ms-adal
And voilá.

1 Like