0

I'm trying to pass input parameters to a component but I'm getting this exception: browser_adapter.ts:78 EXCEPTION: Error: Uncaught (in promise): No Directive annotation found on PropDecoratorFactory

I tried the solutions described here and it didn't solve the issue for me:

Here is my code:

import {Component, provide, Input} from '@angular/core';
import {bootstrap} from '@angular/platform-browser-dynamic';
import {Http, HTTP_PROVIDERS} from '@angular/http';
import {RouteConfig, ROUTER_DIRECTIVES, Router, ROUTER_PROVIDERS} from '@angular/router-deprecated'

@Component({
  selector: 'sub',
  template : `<p>input: {{someInput}}</p>`,
  directives: [Input]
})
export class SubComponent {
  @Input() someInput: Number;
}

@Component({
  selector: 'home',
  template : `<p>home</p><sub [someInput]="someInput"></sub>`,
  directives: [SubComponent]
})
export class HomeComponent {
  someInput: Number = 123;
}

@Component({
    selector: 'my-app',
    template: '<h1>here!</h1><router-outlet></router-outlet>',
    directives: [ROUTER_DIRECTIVES],
    providers: [ROUTER_PROVIDERS]
})
@RouteConfig([
    { path: '/home', name: "Home", component: HomeComponent, useAsDefault: true}
])
export class App {
}

and my Plunker: http://plnkr.co/edit/wNKmsnjHf6HeCQD1gV8c?p=preview

Community
  • 1
  • 1
BSSchwarzkopf
  • 352
  • 2
  • 11

1 Answers1

0

Remove Input from the directives array line

@Component({
  selector: 'sub',
  template : `<p>input: {{someInput}}</p>`,
  directives: [Input] // <---- this is causing it
})
export class SubComponent {
  @Input() someInput: Number;
}

Input is not a directive, its a decorator for component inputs only used inside the class, not on the html.

Ed Morales
  • 1,027
  • 5
  • 9
  • No problem, the `directives` array is just for directives/components you want to use in your html template. – Ed Morales Jun 10 '16 at 21:39