Comments (5)
I am not sure this will help you guys, but it worked for me.
I am using universal and got the same error (ReferenceError: KeyboardEvent is not defined) with the ng-gallery when running the build.
so first:
-
install regexp-replace-loader:
npm install regexp-replace-loader --save-dev
-
then in weback.server.config.js add the below to the module > rules section:
module: { rules: [ { test: /\.ts$/, loader: 'ts-loader' }, //below is the fix for image gallery keyboard error { test: /\.(ts|js)$/, loader: 'regexp-replace-loader', query: { match: { pattern: '\\[(Mouse|Keyboard)Event\\]', flags: 'g' }, replaceWith: '[]', } } ] },
- on your gallery component wrap the gallery.load with the isPlatformBrowser:
import { Component, Inject, OnInit, } from '@angular/core'; import { PLATFORM_ID } from '@angular/core'; //<-- if browser import { isPlatformBrowser, isPlatformServer } from '@angular/common';//<-- if browser import { Gallery } from 'ng-gallery'; //<-- image gallery @Component({ selector: 'image-gallery', templateUrl: './image-gallery.component.html', }) export class ImageGalleryComponent implements OnInit { { src: 'images/logo.png', thumbnail: 'images/logo.png', text: 'ccc' }, // ... ]; constructor( public gallery: Gallery, @Inject(PLATFORM_ID) private platformId: Object //<-- if browser ) { } ngOnInit() { if (isPlatformBrowser(this.platformId)) { //<-- if browser this.gallery.load(this.images); } if (isPlatformServer(this.platformId)) {} } }
Hope it will help someone as it helped me.
Cheers
from ngx-gallery.
Is this error showing in the building process or at runtime? please post the full error
from ngx-gallery.
I have the same error on angular 5.0.2 and universal 5.0.0-beta.5
/usr/src/app/dist/server.js:149337
__metadata$1("design:paramtypes", [KeyboardEvent]),
^
ReferenceError: KeyboardEvent is not defined
at Object.<anonymous> (/usr/src/app/dist/server.js:149337:40)
at __webpack_require__ (/usr/src/app/dist/server.js:20:30)
at Object.9QXJ (/usr/src/app/dist/server.js:146313:29448)
at l (/usr/src/app/dist/server.js:146313:149)
at Object.pfyn (/usr/src/app/dist/server.js:146313:161422)
at l (/usr/src/app/dist/server.js:146313:149)
at Object.5tsa (/usr/src/app/dist/server.js:146313:28218)
at l (/usr/src/app/dist/server.js:146313:149)
at Object.JwoV (/usr/src/app/dist/server.js:146313:98938)
at l (/usr/src/app/dist/server.js:146313:149)
from ngx-gallery.
Thx, its work!
from ngx-gallery.
+1
Angular Universal support needed :)
from ngx-gallery.
Related Issues (20)
- `galleryItemDef` directive not working HOT 3
- ng-gallery not working with [email protected] HOT 1
- add a angular pipe for protected images HOT 3
- Create a storybook documentation HOT 1
- Constant cpu usage on idle page HOT 1
- GalleryConfig in sub components HOT 2
- galleryRef config not working HOT 3
- Black borders on the left/right on some configurations HOT 3
- Performance / too many ChangeDetections [ng-gallery < 8.0.0] HOT 2
- Suggestions for Two Additional Thumbnail Features HOT 1
- Gallery Config overwritten in GalleryService `ref` method
- ng-gallery.mjs:287 [NgGallery]: Unable to set the active item because the given index (1) is outside the items range! HOT 2
- Lightbox: Use the native dialog element instead of CDK dialog
- Thumbnails are not aligned at the start HOT 2
- cant install it -new to angular- HOT 1
- Make it possible to use the gallerize directive in a container in which gallery items are added and removed dynamically. HOT 2
- itemTemplate for Lightbox Gallery HOT 12
- (click) dynamically change class HOT 1
- capture currently visible and clicked image HOT 3
- Fix custom item template documentation
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 ngx-gallery.