Pass variable in Angular 2 template

前端 未结 4 1615
情书的邮戳
情书的邮戳 2020-12-09 04:47

Is there a way I can pass variables to templates in Angular2?

Let\'s say I have the following code:

4条回答
  •  情歌与酒
    2020-12-09 05:05

    But this doesn't work if the template is located in another component. How do you pass a context object in such scenario?

    I added
    @Input() itemTemplate: TemplateRef;

    in component where I will use it, and in template of this component I write something like this:

      
    

    Code of template from outside component:

    
    
    Hello, {{data.name}}

    Just pass link to dataRendererTpl as @Input() property to component in which you need it

提交回复
热议问题