2017-02-11 47 views
1

我有一个宏伟的父组件中,我传递“了selectedValue”父组件如下: - 在祖父母模板Angular2创造的输入值的新实例

@Component({ 
    selector: 'grand-parent', 
    template: '<parent [details]="selectedValue" ></parent>' 
}) 
export class GrandParentComponent implements OnInit { 
    private selectedValue = 0 ; 
    ngOnInit() { 
    setTimeout(function() { 
     this.selectedValue =+ 1; 
     }, 1000); 
    } 
} 

代码在我父组件我是使用循环创建一个子组件并通过了“了selectedValue”象下面这样: -

<template ngFor let-tab [ngForOf]="arry" let-i="index"> 
    <child [details]="selectedValue"></child> 
// some more logic 
</template> 

问题是子组件正在了selectedValue的最后一个值。 例如,如果我通过selectedValue作为1,2,3. 然后在子组件中,我将接收所有三个子组件的细节= 3,因为我正在迭代。 我需要一些如何通过当前“了selectedValue”他们尊重孩子组件 防爆的了selectedValue为1,2,3,我想是这样

<child [details]='1'></child> 
<child [details]='2'></child> 
<child [details]='3'></child> 

不喜欢

<child [details]='3'></child> 
<child [details]='3'></child> 
<child [details]='3'></child> 

一些事情就像每个“selectedValue”的新对象一样。 如何实现这个任何想法,赞赏。

+0

我认为你需要为我们提供更多的代码来看看发生了什么。代码应该展示'selectedValue'的来源。如果你使用'ngFor'而不使用你在'* ngFor'中引入的'tab'变量,那么你不能指望传递不同的值。 –

+0

你可以使用更方便的''而不是'