0

Default component is :

import {Component} from 'angular2/core';
import {MyComponentComponent} from './mycomponentcomponent';

@Component({
    selector: 'my-app',
    template: `
        <h1>Angular 2  Demo</h1>
        <p>Hello World Testing</p>
        <test-app></test-app>

    `,
    directories:[MyComponentComponent]
})
export class AppComponent {

}

And Second Component:

import {Component} from 'angular2/core';

@Component({
    selector: 'test-app',
    template: '
        <h1>TEST APP</h1>
        <p>TEST APP -> Hello World Testing 12</p>
    ',
})
export class MyComponentComponent {

}

But it is showing a javascript error. May i know please where am i doing mistake?

3
  • Please add the exact error message to your question. Commented Oct 5, 2016 at 16:24
  • directories should be directives, I guess you are using older version of angular2, please upgrade it to Angular 2 final Commented Oct 5, 2016 at 16:25
  • which version are you using ? Commented Oct 5, 2016 at 16:29

1 Answer 1

1

For older version of Angular2,

change

directories:[MyComponentComponent]

to

directives:[MyComponentComponent]


For newer version of Angular2,

please remove directories:[MyComponentComponent] from @Component({}) of AppComponent

and add it to @NgModule({}) as shown here,

@NgModule({
   ...
   declarations :[AppComponent, MyComponentComponent]
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.