Adding directives attribute to @Component gives error

1,507 views
Skip to first unread message

Balaji Iyengar

unread,
Sep 23, 2016, 7:30:26 AM9/23/16
to AngularJS
Hi,

I need to include a child component into a parent component. Followed the steps suggested in various online blogs to use something like

@Component
({
      directives: [<Class Name>]
})

But when I do the above I get the below error, Please help.

Using Angular 2, QuickStart Guide steps to create the project in VS2015, Typescript 2.0.3

Error: Argument of type '{ selector: string; template: string; directives: undefined[]; }' is not assignable to parameter of type 'Component'.
  Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.

Lucas Lacroix

unread,
Sep 23, 2016, 10:03:54 AM9/23/16
to AngularJS
Could you provide the actual code? I worry that you are including the angle brackets ("<" and ">") around the class name which would make it a cast operation.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
--
Lucas Lacroix
Computer Scientist
Advanced Technology Division, MEDITECH

Timothy Sheils

unread,
Sep 23, 2016, 1:45:00 PM9/23/16
to AngularJS
I'm running into this issue too. I have a version using Typescript 1.8.10, and it works fine, but the Typescript 2.0.3 version doesn't. Same error as above:

@Component({
templateUrl: 'build/pages/drug-details/drug-details.html',
directives: [DrugDetailBasic, ClinicalPhase, ResearchUse, ClinicalUse, Indications, RecentEvents]
})

Balaji Iyengar

unread,
Sep 25, 2016, 11:16:53 PM9/25/16
to AngularJS
@Lucas

The code is given below, I gave the "< .. >" just to show that its a placeholder.

import { Component } from '@angular/core';

@Component({

selector: 'menu',

template: '<h1>Angular Menu</h1>'

})

export class MenuComponent { }

 

 

@Component({

selector: 'my-app',

template: '<h1>My First Angular App</h1><menu></menu>',

directives: []

})

export class AppComponent { }


Thanks,
Balaji Iyengar

Balaji Iyengar

unread,
Sep 25, 2016, 11:20:15 PM9/25/16
to AngularJS
@Lucas

Update

I get the error in either case with/without providing any name in the brackets, i.e. I also tried with

   

directives: [MenuComponent]


Still get the same error.

Thanks,
Balaji

On Friday, September 23, 2016 at 7:33:54 PM UTC+5:30, Lucas Lacroix wrote:
Reply all
Reply to author
Forward
0 new messages