Giter Club home page Giter Club logo

Comments (11)

wildlifechorus avatar wildlifechorus commented on September 3, 2024 3

I'm not gonna go into much detail but this is pretty simple.

  1. Remove this third party, since it does not work on Angular 5.
  2. On you app.component.ts add the following inside ngOnInit():
    // Init Intercom
    if (isPlatformBrowser(this.platformId)) {
      const d = document;
      const s = d.createElement('script');
      s.type = 'text/javascript';
      s.async = true;
      s.src = `https://widget.intercom.io/widget/` + environment.intercomId;
      const x = d.getElementsByTagName('script')[0];
      x.parentNode.insertBefore(s, x);

      const w = <any>window;
      w.intercomSettings = {
        app_id: environment.intercomId,
        widget: {
          'activator': '#intercom'
        },
        custom_launcher_selector: '#intercom_launcher'
      };
    }

This will work with Angular 5 SSR/AOT!

Don't forget to use:

import { isPlatformBrowser } from '@angular/common';

from ng-intercom.

scott-wyatt avatar scott-wyatt commented on September 3, 2024 1

@wbhob, we could move this lib into a modified boilerplate of https://github.com/CaliStyle/NgEngine. That has SSR/AOT testing built into it and ng-packagr to deploy libraries.

from ng-intercom.

wbhob avatar wbhob commented on September 3, 2024

This is a direct port of the Intercom loading script. If you have a suggestion, I would be open to reviewing a pull request.

from ng-intercom.

RuiEEE avatar RuiEEE commented on September 3, 2024

I'm getting the same issue and I'm guessing this is a SSR issue, can we make this happen? Prevent the server side to run the intercom loading script perhaps?

from ng-intercom.

wbhob avatar wbhob commented on September 3, 2024

If you don't run the loading script, then the Intercom library won't load at all. You'll notice that the Intercom provider is an Angular-friendly wrapper around existing intercom methods. Unless someone knows a way to load the official intercom script at runtime, I don't think this will be available out of the box.

from ng-intercom.

wbhob avatar wbhob commented on September 3, 2024

the issue is that Intercom depends directly on document to inject the intercom messenger script and modify the DOM to insert the messenger button. Other than working directly with intercom, I can't think of any way to support SSR.

from ng-intercom.

scott-wyatt avatar scott-wyatt commented on September 3, 2024

So, when I built this originally, I used dependency injection. On the server side it would just use a bunch of noops, render correctly and then carry out the client side intercom boot when angular does it's startup on the client side. You can also do this by what @wildlifechorus was talking about, by checking if the environment is the browser and not the server. You don't want to render the intercom button on the server anyhow.

from ng-intercom.

wbhob avatar wbhob commented on September 3, 2024

I guess my question is: how do we render intercom if it is in a server-side context? We still want consumers to be able to use Intercom, so how to we go about including the intercom script?

from ng-intercom.

scott-wyatt avatar scott-wyatt commented on September 3, 2024

Angular reboots even if it’s rendered server side, no worries mang, I can prove it and show it :-)

from ng-intercom.

wbhob avatar wbhob commented on September 3, 2024

Sounds awesome

from ng-intercom.

scott-wyatt avatar scott-wyatt commented on September 3, 2024

Closing this as fixed in 1.0.0-beta.12, however beta.12 is having it's own issues.

from ng-intercom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.