Giter Site home page Giter Site logo

Comments (13)

MurhafSousli avatar MurhafSousli commented on May 29, 2024

@u12206050 Yup, it uses window.open() to open the dialog, let me investigate this further for you

from ngx-sharebuttons.

u12206050 avatar u12206050 commented on May 29, 2024

The main problem is the use of window.location.href, I believe angular does have a Location object that you can use. Luckily window.open() doesn't get called when rendering on the server so that isn't such a big deal.

For others wanting to fix this, I did the following to fix the window.location.href:

Replaced window.location.href with
typeof window != 'undefined' ? window.location.href : typeof global != 'undefined' ? global.url : ''

And then in server.ts where Universal is being called to render do the following:

/* Declare both global and the url property for typescript concerns */
interface Global {
  url: string;
}
declare var global: Global;

/* In the function that responds with the rendered html */
let ngApp = (req, res) => {
  let url = req.originalUrl || '/';
  global.url = url;

  ...
}

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

@u12206050 I got it, it turned out that there's no window in node, @ViewChild('firstModal') could be a solution

from ngx-sharebuttons.

u12206050 avatar u12206050 commented on May 29, 2024

Is this fixed now?

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

@u12206050 I haven't played with Universal yet, but now sharebuttons will only use window.location.href if the [url] input is not provided, so pass your current url to the input and it should work

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

@u12206050 For opening share window which uses window.open I'm not sure if it can be fixed in Universal, I talked about it in angular group
capture
I would have used a modal instead of window,open, but fb have SAMEORIGIN policy, which disallows sharing within iframe outside of their domain..

from ngx-sharebuttons.

u12206050 avatar u12206050 commented on May 29, 2024

Could you just please do the following, it fixes compiling on universal side at least.
Replaced window.location.href with
typeof window != 'undefined' ? window.location.href : typeof global != 'undefined' ? global.url : ''

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

@u12206050 okay it's merged now, please download the source manually and test it in your app, if it works I will push it to npm, because I'm not sure if it would work with window.open. isn't it a problem for universal to compile?

btw, I tried to replace window.location.href with router.url, location.path() and location.prepareExternalUrl(location.path()), they all don't return the full path, also couldn't find any alternative to window.open. we can't get rid of it

from ngx-sharebuttons.

u12206050 avatar u12206050 commented on May 29, 2024

Ok, the changes should work, except that window and global are undefined in the context of typescript when compiling. I made a merge request with the interfaces for them.

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

I tried to use it on a fresh Universal Starter installation, I imported ShareButtonsModule in both app.browser.module and app.node.module, it worked.
The only issue I found is when I click on Pinterest button. Cannot read property 'getAttribute' of null, but everything else is working as expected!
BTW this is without the changes we made earlier 👆
capture

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

Changes are merged and pushed to npm in 1.0.7

from ngx-sharebuttons.

u12206050 avatar u12206050 commented on May 29, 2024

Did you make use of the share buttons on universal side or do you only render them client side?

from ngx-sharebuttons.

MurhafSousli avatar MurhafSousli commented on May 29, 2024

Did you make use of the share buttons on universal side

@u12206050 I just used it the same way I would use it in a normal angular app and it worked, I'm not sure what you mean by make use of them on universal side because I'm not technically familiar with universal yet. I have been told that global variables like window are not available in node apps, and we can't get rid of window completely since there is no other way to open the sharing dialog in a new window (not new tab).

from ngx-sharebuttons.

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.