0

If I declare component inline I can execture directive on it

<stuff1-component my-directive></stuff1-component>

Is there any way to do something similar but in case of using angular2 component router?

@RouteConfig([  
  { path: '/route1', name: 'Stuff1', component: Stuff2Component, directive: my-directive },
  { path: '/route2', name: 'Stuff2', component: Stuff2Component },
])

The reason I need to do that because I need to apply some behaivour to MDL component which I implemented as directive Integrating Material Design Lite with Angular2.

import {Directive, AfterViewInit} from 'angular2/core';
declare var componentHandler;

@Directive({
    selector: '[mdl]'
})    
export class MDL implements AfterViewInit {

    ngAfterViewInit() {
        componentHandler.upgradeAllRegistered();
    }
}
Community
  • 1
  • 1
Sergino
  • 10,128
  • 30
  • 98
  • 159
  • can you explain more? – micronyks Mar 16 '16 at 06:28
  • what you want to do exactly pls exaplin bit more or post your code. – Pardeep Jain Mar 16 '16 at 06:35
  • @micronyks just updated the Q – Sergino Mar 16 '16 at 06:40
  • to be clear, I really don't get the idea. But what I can feel is you may go with `host`. But still not sure. still wait someone else can guide you better ! – micronyks Mar 16 '16 at 06:44
  • @micronyks for each MDL component I need to call `componentHandler.upgradeAllRegistered();` so I have directive which does that. Inline I am doing `` - no problems at all, but in case of component routing I do not know how to do that. – Sergino Mar 16 '16 at 06:46
  • Oh I see ! means what you want is, when a particular cmp becomes active, you want to run `componentHandler.upgradeAllRegistered();`, isn't it? – micronyks Mar 16 '16 at 06:49
  • @micronyks Yes otherwise MDL components won't fully working. E.g table http://www.getmdl.io/components/index.html#tables-section wont display checkboxes, etc So I need to apply my directive that does `componentHandler.upgradeAllRegistered();` – Sergino Mar 16 '16 at 06:51
  • Have you considered about using `viewchild api`? in a particular cmp, you can create an instance of your `custom directive` and with that you can call directive's code from a particular cmp with `ngAfterViewInit` hook – micronyks Mar 16 '16 at 06:54
  • @micronyks haven't tried `viewchild` – Sergino Mar 16 '16 at 06:59
  • @micronyks what this line is actulally doning `@ViewChild('selectedColorDirective') private vc:selectedColorDirective;` ? – Sergino Mar 16 '16 at 07:09
  • @micronyks a u able to join back to discussion? – Sergino Mar 16 '16 at 07:40

0 Answers0