CaliStyle / ng-intercom

Angular 7+ Wrapper for Intercom.com
MIT License
54 stars 46 forks source link

Received "window.Intercom is not a function" error #11

Closed craigeddy closed 7 years ago

craigeddy commented 7 years ago

Until I added the following to my app's index.html:

<script>
(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;
    s.src='https://widget.intercom.io/widget/<app_id>';
    var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()
</script>
wbhob commented 7 years ago

Yes, that is the intended behavior. You need to instantiate Intercom before you can access the services.

craigeddy commented 7 years ago

👍

I'd recommend adding a note/step to the readme perhaps. Save the less-savvy in Angular folks such as myself.

wbhob commented 7 years ago

Done! @craigeddy

wbhob commented 7 years ago

I actually implemented this functionality in to the 1.0.0-alpha, releasing soon, so it automatically injects the script for you. Is this something you would be interested in trying? @craigeddy

wbhob commented 7 years ago

@craigeddy v1.0.0-alpha is out, would you mind giving it a try?

craigeddy commented 7 years ago

Certainly. Total Angular/npm noob (C# & NuGet are my jam). How would I upgrade to this version?

wbhob commented 7 years ago

https://github.com/CaliStyle/angular2-intercom/blob/1.0.0-alpha/docs/1-Installaton.md

craigeddy commented 7 years ago

When I use this version, I'm getting a compile error on ng serve:

ERROR in Error encountered resolving symbol values statically. Calling function 'IntercomModule', function calls ar e not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symb ol AppModule in C:/Users/eddycr/Source/Repos/registration/src/app/app.module.ts, resolving symbol AppModule in C:/U sers/eddycr/Source/Repos/registration/src/app/app.module.ts

the code:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { IntercomModule } from 'ng-intercom';
import { AppComponent } from './app.component';
import { RegisterModel } from './app.registermodel';
import { RegistrationComponent } from 'app/registration/registration.component';

@NgModule({
  declarations: [
    AppComponent,
    RegistrationComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    IntercomModule.forRoot({ app_id: 'sq739kpn'})
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

I also have a repo with my whole project if you want to take a look. I'm probably doing/forgetting something noob-ish. https://github.com/craigeddy/IntercomProtype (angular2-intercom-alpha branch)

wbhob commented 7 years ago

@craigeddy I'll look into it soon. I openned another issue at #12. Thanks for the feedback!