Skip to content
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

Closed
chompy1 opened this issue Aug 15, 2017 · 10 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@chompy1
Copy link

chompy1 commented Aug 15, 2017

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")

[X] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

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

  1. Create a new angular-cli project
    ng new primeng-fileupload

  2. Install bootstrap 4;
    npm install bootstrap@4.0.0-alpha.6 --save

  3. Install primeng;
    npm install primeng --save

  4. Add bootstrap css to styles.css;
    @import "~bootstrap/dist/css/bootstrap.min.css";

  5. Import fileupload module in app.module.ts;
    import { FileUploadModule } from '../../node_modules/primeng/components/fileupload/fileupload';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FileUploadModule
],
. . .

  1. 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">

  2. Run the project
    ng serve

  3. 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]

@a-kolybelnikov
Copy link

a-kolybelnikov commented Aug 20, 2017

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.

@maciekstary
Copy link

Same issue with PrimeNG 4.1.3 and Angular 4.3.5

@ningacoding
Copy link

@a-kolybelnikov, is as simple as they (primeng team) add this to the p-fileUpload component:

clear() {
        this.files = [];
        this.onClear.emit();
        if (this.fileinput && this.fileinput.nativeElement) { // this validation fixes the issue
            this.fileinput.nativeElement.value = '';
        }
    }

cagataycivici added a commit that referenced this issue Aug 22, 2017
Fix #3664 Added the missing template reference
@cagataycivici cagataycivici self-assigned this Aug 22, 2017
@cagataycivici cagataycivici added the Type: Bug Issue contains a bug related to a specific component. Something about the component is not working label Aug 22, 2017
@cagataycivici cagataycivici added this to the 4.1.4 milestone Aug 22, 2017
cagataycivici pushed a commit that referenced this issue Aug 22, 2017
@a-kolybelnikov
Copy link

a-kolybelnikov commented Aug 23, 2017

@ikuriel thanks a lot, brilliant. Meanwhile I just implemented a simple HTML5 FileHolder and styled it with CSS. It works just fine.

@ivansnek
Copy link

@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?

@ningacoding
Copy link

ningacoding commented Aug 24, 2017

@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:

<p-fileUpload #pfuReference onSelect($event, pfuReference) ... etc...></p-fileUpload>

in the Class you can do next:

onSelect(event, pfuReference) {
    if(pfuReference.msgs && pfuReference.msgs.lenght > 0) { // msgs are the messages of errors/validations
        pfuReference.clear();
        return; // return if you wanna break
    }
    // other things...
}

@ivansnek
Copy link

Thanks @ikuriel that helped me to solve it, with a little modification, also I'm closing this issue with the description #3736

@ivansnek
Copy link

ivansnek commented Sep 7, 2017

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 mode="basic", I made a workaround hiding the element, hope soon it gets resolved.

@fadelc99
Copy link

fadelc99 commented Sep 8, 2017

@ivansnek i have same issue and try to do with #3736 with out mode="basic" and then when click button dialog select file not show. how do you solve this issue?

@ivansnek
Copy link

ivansnek commented Sep 9, 2017

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 acept=“image/*” property on the component?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

7 participants