Angular2 - 使用多个组件引导应用程序

时间:2017-02-28 11:16:21

标签: angular

我是Angular2的新手,我对如何启动我想要创建的应用程序有一些想法。

基本上我需要创建一个包含多个面板的简单仪表板。 面板本身是一个显示一些结果的常见对象。

这是面板对象的示例模型(我正在使用TS):

name :string;
data: Array<string>;

以下是结构简单图表的link

仪表板组件创建3个面板,将一组数据传递给每个面板。面板从仪表板接收数据,运行render()函数并在他自己的视图中显示数据。

这是一种正确的架构方法吗?

1 个答案:

答案 0 :(得分:1)

您只需使用public static class AutoMapperConfig { public static void RegisterMappings() { AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap<R_Logo, LogoDto>(); /* etc */ }); } } 名称创建元素,即可在父模板中指定子组件。要传递数据,您可以使用selector中的@Input装饰器。

查看官方docs

以下是您的仪表板(父级)的外观:

@angular/core

小组(儿童)

import { Component } from '@angular/core';

@Component({
   selector: 'dashboard-component', 
   template: `
      <panel-component [name]="'Panel One'" [data]="['1', '2']" ></panel-component>
      <panel-component [name]="'Panel Two'" [data]="['3', '4']" ></panel-component>
      <panel-component [name]="'Panel Three'" [data]="['5', '6']" ></panel-component>          `
})
class DashboardComponent { }

Here is a plunker你可以试试!