-
Notifications
You must be signed in to change notification settings - Fork 4.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
FileUpload Cannot read property 'nativeElement' of undefined; PrimeNG 4.1.3 Release - #3664
Comments
same issue. saying good-bye to primeng's file-upload: cannot find a quick solution and cannot wait for one either because of the project deadline. |
Same issue with PrimeNG 4.1.3 and Angular 4.3.5 |
@a-kolybelnikov, is as simple as they (primeng team) add this to the p-fileUpload component:
|
Fix #3664 Added the missing template reference
@ikuriel thanks a lot, brilliant. Meanwhile I just implemented a simple HTML5 FileHolder and styled it with CSS. It works just fine. |
@ikuriel is there a way to call the clear() method on any of the events? I want to validate the image size on the "onSelect" event, but I can't find a way to cancel the event propagation and prevent the file to be uploaded, any thoughts on this? |
@ivansnek you can pass the ElementReference with: <p-fileUpload #pfuReference ... etc> and in the "onSelect", something like this: onSelect($event, pfuReference) So complete HTML template is like:
in the Class you can do next:
|
Thanks @ikuriel that helped me to solve it, with a little modification, also I'm closing this issue with the description #3736 |
For any one who enter here and still having the same issue, for me on version 4.1.2, the issue was caused by use the |
Are you also trying to validate images only? I think I didn’t get your question, as far I understood you’re not able to see the file to selec on the dialog box right? What kind of file is it? Are you using the |
Base Issue:
#3385
Notes:
Issue still exists with 4.1.3 release, rolled back to 4.1.2 to remove exceptions in console.
I'm submitting a ... (check one with "x")
Plunkr Case (Bug Reports)
Please fork the plunkr below and create a case demonstrating your bug report. Issues without a plunkr have much less possibility to be reviewed.
http://plnkr.co/edit/q9KmvhK5Z1hnsIJTj06H?p=preview
Updated systemjs.config.js to use latest build:
'primeng': 'npm:primeng@4.1.3'
Current behavior
Using the basic FileUpload, when selecting a single file the system throws errors in the console
Same premise, but different line numbers from Plunker and a demo project:
PLUNKER
FileUpload.html:40 ERROR TypeError: Cannot read property 'nativeElement' of undefined
at FileUpload.onFileSelect (fileupload.ts:194)
at Object.eval [as handleEvent] (FileUpload.html:41)
at handleEvent (view.ts:142)
at callWithDebugContext (services.ts:815)
at Object.debugHandleEvent [as handleEvent] (services.ts:411)
at dispatchEvent (util.ts:185)
at eval (element.ts:238)
at HTMLInputElement.eval (dom_renderer.ts:75)
at ZoneDelegate.invokeTask (zone.js@0.8.4?main=browser:398)
at Object.onInvokeTask (ng_zone.ts:288)
at ZoneDelegate.invokeTask (zone.js@0.8.4?main=browser:397)
at Zone.runTask (zone.js@0.8.4?main=browser:165)
at HTMLInputElement.ZoneTask.invoke (zone.js@0.8.4?main=browser:460)
DEMO PROJECT:
FileUpload.html:40 ERROR TypeError: Cannot read property 'nativeElement' of undefined
at FileUpload.webpackJsonp.../../../../primeng/components/fileupload/fileupload.js.FileUpload.onFileSelect (fileupload.js:86)
at Object.eval [as handleEvent] (FileUpload.html:41)
at handleEvent (core.es5.js:11997)
at callWithDebugContext (core.es5.js:13458)
at Object.debugHandleEvent [as handleEvent] (core.es5.js:13046)
at dispatchEvent (core.es5.js:8601)
at core.es5.js:9212
at HTMLInputElement. (platform-browser.es5.js:2651)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:424)
at Object.onInvokeTask (core.es5.js:3881)
Expected behavior
No exceptions being thrown in the console window
Minimal reproduction of the problem with instructions
Create a new angular-cli project
ng new primeng-fileupload
Install bootstrap 4;
npm install bootstrap@4.0.0-alpha.6 --save
Install primeng;
npm install primeng --save
Add bootstrap css to styles.css;
@import "~bootstrap/dist/css/bootstrap.min.css";
Import fileupload module in app.module.ts;
import { FileUploadModule } from '../../node_modules/primeng/components/fileupload/fileupload';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FileUploadModule
],
. . .
Add HTML markup to app.component.html for basic fileupload with auto;
<p-fileUpload #fubauto mode="basic" name="demo[]" url="./upload.php" accept="image/*" maxFileSize="1000000" (onUpload)="onBasicUploadAuto($event)" auto="true" chooseLabel="Browse">
Run the project
ng serve
Click "Browse" button and select a file
What is the motivation / use case for changing the behavior?
Bug fix
Please tell us about your environment:
Windows 7, Visual Code 32/64-bit, webpack
Windows 10, Visual Code 32-bit, webpack
Angular version: 4.0.X
PrimeNG version: 4.1.3
Browser: [Chrome XX | Firefox XX | IE XX ]
Language: [all | TypeScript X.X | ES6/7 | ES5]
The text was updated successfully, but these errors were encountered: