Comments (11)
I'm not gonna go into much detail but this is pretty simple.
- Remove this third party, since it does not work on Angular 5.
- On you
app.component.ts
add the following insidengOnInit()
:
// 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.
@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.
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.
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.
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.
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.
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.
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.
Angular reboots even if itβs rendered server side, no worries mang, I can prove it and show it :-)
from ng-intercom.
Sounds awesome
from ng-intercom.
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)
- Error starting tour HOT 1
- Intercom is not compatible with Angular 9 since .forRoot() got deprecated. HOT 3
- Angular 11 is incompatible HOT 3
- Not showing Intercom(icon widget) before login
- Upgrade to Angular v16 HOT 7
- Breaks under Angular 17 HOT 1
- appId being ignored in boot method HOT 3
- Function calls are not supported in decorators but 'IntercomModule' was called. - Regression in beta.6 HOT 38
- Support for angular 7.0 HOT 2
- Event metadata must be an object HOT 1
- Problems when building HOT 4
- Error with ng build --prod HOT 2
- Function calls are not supported in decorators but 'IntercomModule' was called. HOT 1
- Provider parse errors, Cannot instantiate cyclic dependency HOT 2
- Please ensure your intercomSettings object is formatted correctly: Missing App ID. HOT 8
- [fix] use window.intercomSettings to initiate app ID
- Lib broken in 8.0.0-rc.0 HOT 1
- Star tour function needed HOT 8
- Route performance problems using updateOnRouterChange HOT 5
- [8.0.1] Cannot find module 'ng-intercom' HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-intercom.