如何在另一个组件中显示组件的内容?

时间:2017-10-17 09:30:53

标签: angular

我想在另一个组件中显示组件的内容。 这是我要在menu.component.html中显示的app.component.html

<div class="Tree">
<tree-root [nodes]="nodes">
<ng-template #treeNodeTemplate let-node let-index="index">
<a><span>{{ node.data.description }}</span></a>
</ng-template>
</tree-root>
</div>

我正在使用angular-tree-component以树形式显示数据。

这是我的app.component.html我正在使用菜单组件的<menu>选择器来显示菜单:

<menu [path]="path"></menu>

问题是我只获取树的第一个元素而不是以树形式获取数据。

1 个答案:

答案 0 :(得分:0)

为什么不使用事件发射器在组件之间传输数据

<DockPanel VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Height="422" Width="780" Margin="200,0,0,0" Background="#FF89BBF7">
    <TabControl VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="20,0,0,0" Background="#FF89BBF7">
        <TabItem Header="Active Calls">
            <TabItem.Background>
                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                    <GradientStop Color="#FFF3F3F3" Offset="0"/>
                    <GradientStop Color="#FFEBEBEB" Offset="0.5"/>
                    <GradientStop Color="#FFDDDDDD" Offset="0.5"/>
                    <GradientStop Color="#FF89BBF7" Offset="1"/>
                </LinearGradientBrush>
            </TabItem.Background>
            <Grid Background="#FF89BBF7" HorizontalAlignment="Stretch">
                <StackPanel>
                <ListView Name="lvwCalls"  HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="Auto" Margin="10,10,10,40" >
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Priority" Width="50" DisplayMemberBinding="{Binding priority}" />
                                <GridViewColumn Header="Call Status" Width="60" DisplayMemberBinding="{Binding callStatus}" />
                                <GridViewColumn Header="Call Type" Width="60" DisplayMemberBinding="{Binding callType}" />
                                <GridViewColumn Header="Dispatched Persons" Width="120" DisplayMemberBinding="{Binding dispatchedPersons}" />
                                <GridViewColumn Header="Region" Width="50" DisplayMemberBinding="{Binding region}" />
                                <GridViewColumn Header="Location" Width="80" DisplayMemberBinding="{Binding location}"/>
                                <GridViewColumn Header="Specific Location" Width="100" DisplayMemberBinding="{Binding specLocation}" />
                                <GridViewColumn Header="Time" Width="50" DisplayMemberBinding="{Binding time}" />
                                <GridViewColumn Header="Dispatch #" Width="60" DisplayMemberBinding="{Binding dispatchNumber}" />
                                <GridViewColumn Header="Address" Width="60" DisplayMemberBinding="{Binding address}" />
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <Label Content="Pending Calls:"/>
                    <ListView HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="Auto" Margin="10,10,10,50" >
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Priority" Width="120" DisplayMemberBinding="{Binding Priority}" />
                                <GridViewColumn Header="Call Type" Width="120" DisplayMemberBinding="{Binding CallType}" />
                                <GridViewColumn Header="Location" Width="150" DisplayMemberBinding="{Binding Location}" />
                                <GridViewColumn Header="Specific Location" Width="100" DisplayMemberBinding="{Binding SpecLocation}" />
                                <GridViewColumn Header="Time" Width="100" DisplayMemberBinding="{Binding Time}" />
                                <GridViewColumn Header="Dispatch #" Width="100" DisplayMemberBinding="{Binding DispatchNumber}" />
                            </GridView>
                        </ListView.View>
                    </ListView>
                </StackPanel>
            </Grid>
        </TabItem>
        <TabItem Header="History">
            <Grid Background="#FF89BBF7">
                <StackPanel>
                    <ListView HorizontalAlignment="Stretch" VerticalAlignment="Top" Height="Auto" Margin="10,10,10,20" >
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="Call Time" Width="70" DisplayMemberBinding="{Binding CallTime}" />
                                <GridViewColumn Header="Location" Width="80" DisplayMemberBinding="{Binding Location}" />
                                <GridViewColumn Header="Specific Location" Width="100" DisplayMemberBinding="{Binding SpecLocation}" />
                                <GridViewColumn Header="Dispatch Number" Width="120" DisplayMemberBinding="{Binding DispatchNumber}" />
                                <GridViewColumn Header="Description" Width="80" DisplayMemberBinding="{Binding Description}" />
                                <GridViewColumn Header="Report Number" Width="100" DisplayMemberBinding="{Binding ReportNumber}" />
                                <GridViewColumn Header="Group" Width="60" DisplayMemberBinding="{Binding Group}" />
                                <GridViewColumn Header="Address" Width="80" DisplayMemberBinding="{Binding Address}" />
                            </GridView>
                        </ListView.View>
                    </ListView>
                </StackPanel>
            </Grid>
        </TabItem>
    </TabControl>

</DockPanel>