How can I pass a generic type parameter to an Angular2 component?

前端 未结 3 983

Let\'s say I got a component with a fixed input parameter type,

@Component({
    selector: \'fixed\',
    template: \'
{{value}}
\' }) e
3条回答
  •  醉话见心
    2020-12-16 12:38

    I'm just playing with angular and I made this working by using ViewChild, by having Inner and Outer Component.

    In inner component declaration of component is like:

    @Injectable() 
    @Component({
    selector: 'inner-selector',
    templateUrl: ...,
    styleUrls: ...,
    directives: [
    ...]
    export class InnerComponent****  ...
    

    in outer component which called by router I did:

    import {Component} from '@angular/core';
    import {InnerComponent} from '../components/inner.component';
    import {ViewChild  } from '@angular/core';
    
    @Component({
      selector:     'demo-app',
       template:  '',
    directives: [InnerComponent]
    })
    export class TestPage { 
    
      @ViewChild(InnerComponent)
      **private innerComponent:InnerComponent;**
    };
    

    I don't know is this a good way, but it worked.

    Regards!

提交回复
热议问题