0

i´ve followed this simple example, how i could pass upload-file in my component. How to make FileReader work with Angular2

My component.html file looks like this:

<div class="col-md-6"> <div> Select file: <input type="file" (change)="changeListener($event)"> </div> </div> 

and my component.ts file

import {Component, Input, EventEmitter, Output} from "@angular/core"; import {Router, ROUTER_PROVIDERS} from '@angular/router' import { FormBuilder, FORM_DIRECTIVES } from '@angular/common'; @Component({ moduleId: module.id, selector: 'edit-task', templateUrl: 'task.component.html', directives: [BlueFontDirective], providers: [ROUTER_PROVIDERS] }) export class TaskFormat{ //onChange file listener changeListener($event) : void { console.log('TRRRIIIGERT'); } } 

And when i select some file i get error:

browser_adapter.ts:78ORIGINAL EXCEPTION: TypeError: self.context.changeListener is not a functionBrowserDomAdapter.logError @ browser_adapter.ts:78 browser_adapter.ts:78ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ browser_adapter.ts:78

UPDATE

I just tried it something else. My html-template looks like this:

 <input type="file" (change)="fileChangeEvent($event)" placeholder="Upload file..." /> <button type="button" (click)="upload()">Upload</button> 

And when i select any file and click the Button "open" within selection-promt, i get error, too without to trigger something in my angular2-backend:

browser_adapter.ts:78 TypeError: self.context.fileChangeEvent is not a function at _View_TaskFormat0._handle_change_9_0 (TaskFormat.template.js:698) at eval (view.ts:374) at eval (dom_renderer.ts:308) at eval (dom_events.ts:16) at ZoneDelegate.invoke (zone.js:232) at Object.onInvoke (ng_zone_impl.ts:67) at ZoneDelegate.invoke (zone.js:231) at Zone.runGuarded (zone.js:128) at NgZoneImpl.runInnerGuarded (ng_zone_impl.ts:100) at NgZone.runGuarded (ng_zone.ts:216) 

"FileChangeEvent" will be triggered, when i select any file, but a error will be thrown...

3
  • 1
    What version of angular are you using, the stable version of angular 2 doesn't have directives in the @component anymore . Commented Oct 29, 2016 at 17:11
  • within my dependencies i see: "@angular/core": "2.0.0-rc.1", Commented Oct 30, 2016 at 16:49
  • 1
    That's from the dark ages. You should upgrade. Hardly anyone will remember how things worked back then. Commented Oct 30, 2016 at 16:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.