I use aspnetcore-spa template as starting point to create admin panel. Next I add PrimeNG library to use it's components.
Unfortunately, when I import i.e. ButtonModule to app.module.ts and refresh, I get an error 'Event is undefined'. I can't figure out what is the reason for several days, so can anyone help me?
UPDATE
- So first of all I generate the stub with
yo aspnetcore-spa
- Next
npm install font-awesome primeng --save
Then I add font-awesome and PrimeNG css files to
webpack.config.vendor.js
vendor: [ '@angular/common', '@angular/compiler', '@angular/core', '@angular/http', '@angular/platform-browser', '@angular/platform-browser-dynamic', '@angular/router', '@angular/platform-server', 'angular2-universal', 'angular2-universal-polyfills', 'bootstrap', 'bootstrap/dist/css/bootstrap.css', 'es6-shim', 'es6-promise', 'event-source-polyfill', 'jquery', 'zone.js', 'font-awesome/css/font-awesome.css', 'primeng/resources/themes/sunny/theme.css', 'primeng/resources/primeng.css' ]
Rebuild vendor dependencies
webpack --config webpack.config.vendor.js
- Then I import ButtonModule to app.module.ts
Now if I start the app I'll get exception
Exception point to this fragment of code
__decorate([
core_1.HostListener('mouseenter', ['$event']),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Event]),
__metadata('design:returntype', void 0)
UPDATE 2
I've figured out that problem was in server-side rendering, so I removed it. It works for me, but it is still interesting how to solve this without turning of server-side rendering.
you need to disable the pre render from the server side, from index.cshtml.
change
to
I found out a solution and got it working on one my pet project.
Just follow these steps (I skip the installation since you've already done that):
1- Add the loader for
gif
files since they are required in relatedcss
files:2- Add the styles to your
webpack.config.vendor.js
:3- add the modules you want to top of the
app.module.ts
:4- Add it to your
imports
as well:And voila...
You can find the working code here.
According to http://blog.stevensanderson.com/2016/10/04/angular2-template-for-visual-studio/
There are limitations with server-side rendering. Notably, your application code can’t just assume it always runs in a browser. If you try to reference the browser’s DOM directly, you’ll get an error like window is undefined when it runs server-side. Fortunately that’s rarely a problem, because in a well-architected Angular app (or React, etc.), the framework really doesn’t want you to mess with the DOM directly anyway, so you shouldn’t be assuming browser primitives regardless of server-side rendering.
Lookimng at the javascript file in primeng, some control is manipulating the DOM tree
I am using the same template as you, if you do the following, you can keep the
The answer is, instead of doing
do
AccordionModule is dependent on BlockUI if you open accordion.d.ts, so we have to import it as well
It works for me without removing the prerendering
then go to web.config.vendor.js, modify
to
also in web.config.vendor.js, vendor section, add
then open visual studio command prompt, and navigate to the solution path
However, there are some controls which will still throw an error In this case, no choice but to modify the js file