benbaran / adal-angular4-example

Angular 4 ADAL Wrapper Example
28 stars 13 forks source link

Cannot find namespace 'adal' #3

Closed brndoko closed 7 years ago

brndoko commented 7 years ago

I followed your instructions to reproduce the project and on my app.component.ts when I attempt to use:

const config: adal.config = {}

It says it cannot find the namespace 'adal'. Do you have any idea of why this might occur? Is there something else I need to install in the project?

Any help you can offer would be much appreciated. Thanks so much!

brndoko commented 7 years ago

So, I solved this by adding the adal.d.ts file. I am attempting to allow someone to specify a tenant and client id as the endpoints in my app. So, I attempted to put the service configuration and initialization in a separate component from the app component and only initialize after receiving user input from a form. However, this doesn't seem to be working:

export class AuthAzureComponent implements OnInit {

constructor(private service: Adal4Service, private http: Adal4HTTPService) { }

ngOnInit() { }

onSubmit(form: NgForm) {

const config: adal.Config = {                        
    tenant: form.value.tenant,                      
    clientId: form.value.clientId   
} 

this.service.init(config);

this.service.login();

console.log('username ' + this.service.userInfo.username);

console.log('authenticated: ' + this.service.userInfo.authenticated);

console.log('name: ' + this.service.userInfo.profile.name);

console.log('token: ' + this.service.userInfo.token);

console.log(this.service.userInfo.profile);

}

}

Am I approaching this incorrectly with your wrapper? I'm new to Angular, so any help would be appreciated. Thanks!

seanuleh commented 7 years ago

Hey Brandon,

I am getting the same error you mentioned. Can you explain further how you got passed it? What are the contents of the adal.d.ts file you added?

erikholmgren commented 7 years ago

You just need to add an import statement in app.component: import { adal } from 'adal-angular';

This worked for me.

benbaran commented 7 years ago

This doesn't always seem to happen, but erikholmgren's solutions works when it does.