-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(universal): should play nice with angular/universal #61
Comments
I knew about this problem, server side rendering + mobile ready + aria is key features |
Right now the problem with MouseEvent and KeyboardEvent is the generated JavaScript code:
When you |
Can you generate code without meta? |
The deal is that we can add monkey patch functionality for window on the server for anything but we purposely didn't add any to start with because in most cases you should try to use the Angular API and if a use case comes up that requires direct access to the DOM objects then we need to decide if it is truly something everyone should need or if you should just add it yourself for your project. In this case, it isn't a question of whether to implement the keyboard and mouse event functionality. Rather, whether we should have empty global objects so that the code doesn't fail. Can you link the ng2-bootstrap code that references KeyboardEvent and MouseEvent? Maybe we can think of alternative solutions. |
Ah, OK, now I get it. So, @gdi2290 let me know what you think, but my solution for this would be to simply include an interfaces file. No need to even provide an implementation because it is just a typing issue. Perhaps someone has already done this? |
the angular repo uses var win = window;
export {win as window};
export var document = window.document;
export var location = window.location;
export var gc = window['gc'] ? () => window['gc']() : () => null;
export var performance = window['performance'] ? window['performance'] : null;
export const Event = window['Event'];
export const MouseEvent = window['MouseEvent'];
export const KeyboardEvent = window['KeyboardEvent'];
export const EventTarget = window['EventTarget'];
export const History = window['History'];
export const Location = window['Location'];
export const EventListener = window['EventListener']; which has a problem with global that is solved via declare var WorkerGlobalScope;
var globalScope: BrowserNodeGlobal;
if (typeof window === 'undefined') {
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
// TODO: Replace any with WorkerGlobalScope from lib.webworker.d.ts #3492
globalScope = <any>self;
} else {
globalScope = <any>global;
}
} else {
globalScope = <any>window;
}; If they're types, then it should be okay since they are removed in es5. If you're creating these types, then you should use the DomAdapter. |
@gdi2290 thanks a lot, I will fix it |
Hey, I have a problem with angular2-universal and the collapse component. I know it is because of the use of this._el.nativeElement. I read in the Universal documentation that we should use the Renderer instead of the nativeElement. But the Renderer has no getters (for styles). I tried to use the DomAdapter, here is my code: But it throws an error in the express API: My quick fix is, that I have a condition in the toggle function:
Any thoughts on that? |
I made an alternative implementation for the collapse component, it works with universal and is more like the original bootstrap component: https://gist.github.com/devCrossNet/0b57b60f0199423d37261880a6edca55 I use try-catch with the DOM functions now, to get no errors on the server-side. |
I have some time to work on this now if @valorkin has some time to pair online for an hour or two |
For you @gd2i290 I will find a time :) |
Any updates on the progress of this issue? We're watching this closely as we'd like to be able to use ng2-bootsrap with Angular Universal. Currently, attempting to even just use
We use a build process similar to that in https://github.com/angular/universal-starter |
Hi, |
for universal don't use |
working hack
|
Currently ng2-bootstrap uses
MouseEvent
,KeyboardEvent
andwindow
which prevents it from using in universal angular2 application because those aren't defined server-side.The text was updated successfully, but these errors were encountered: