Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何动态组合(编译)独立组件的模态对话框?_Angular_Typescript - Fatal编程技术网

Angular 如何动态组合(编译)独立组件的模态对话框?

Angular 如何动态组合(编译)独立组件的模态对话框?,angular,typescript,Angular,Typescript,我正在开发带有模式对话框的Angular 2+TypeScript应用程序 我有主要的模态组件: <div class="modal"> <div class="header">{{title}}</div> <div class="body">{{body}}</div> <div class="footer">{{footer}}</div> </div> 所以,我的问题

我正在开发带有模式对话框的Angular 2+TypeScript应用程序

我有主要的模态组件:

<div class="modal">
    <div class="header">{{title}}</div>
    <div class="body">{{body}}</div>
    <div class="footer">{{footer}}</div>
</div>
所以,我的问题是如何从其他组件获取组件的html内容?如何将这些html编译成一个视图?
这样做的最佳方法是什么?我应该使用与模板表达式不同的东西吗?

model.ts

<div class="modal">
    <div class="header">{{title}}</div>
    <div class="body">{{body}}</div>
    <div class="footer">{{footer}}</div>
</div>

model.ts

<div class="modal">
    <div class="header">{{title}}</div>
    <div class="body">{{body}}</div>
    <div class="footer">{{footer}}</div>
</div>

您可以使用
ng内容
。如果你熟悉angular 1,它类似于转换

在主模式中,可以执行以下操作:-

<div class="modal">
    <div class="header">
       <ng-content select="[m-header]"></ng-content>
    </div>
    <div class="body">
       <ng-content select="[m-body]"></ng-content>
    </div>
    <div class="footer">
       <ng-content select="[m-footer]"></ng-content>
    </div>
</div>
<h1>Hello {{name}}</h1> 
<modal>
    <div m-header>
       Your title here
    </div>
    <div m-body>
      <p>Your html content here</p>
    </div>
</modal>

然后在父组件中,您可以像这样使用它:-

<div class="modal">
    <div class="header">
       <ng-content select="[m-header]"></ng-content>
    </div>
    <div class="body">
       <ng-content select="[m-body]"></ng-content>
    </div>
    <div class="footer">
       <ng-content select="[m-footer]"></ng-content>
    </div>
</div>
<h1>Hello {{name}}</h1> 
<modal>
    <div m-header>
       Your title here
    </div>
    <div m-body>
      <p>Your html content here</p>
    </div>
</modal>
Hello{{name}
你的头衔在这里
您的html内容在这里


请参阅本文中的详细信息

您可以使用
ng content
。如果你熟悉angular 1,它类似于转换

在主模式中,可以执行以下操作:-

<div class="modal">
    <div class="header">
       <ng-content select="[m-header]"></ng-content>
    </div>
    <div class="body">
       <ng-content select="[m-body]"></ng-content>
    </div>
    <div class="footer">
       <ng-content select="[m-footer]"></ng-content>
    </div>
</div>
<h1>Hello {{name}}</h1> 
<modal>
    <div m-header>
       Your title here
    </div>
    <div m-body>
      <p>Your html content here</p>
    </div>
</modal>

然后在父组件中,您可以像这样使用它:-

<div class="modal">
    <div class="header">
       <ng-content select="[m-header]"></ng-content>
    </div>
    <div class="body">
       <ng-content select="[m-body]"></ng-content>
    </div>
    <div class="footer">
       <ng-content select="[m-footer]"></ng-content>
    </div>
</div>
<h1>Hello {{name}}</h1> 
<modal>
    <div m-header>
       Your title here
    </div>
    <div m-body>
      <p>Your html content here</p>
    </div>
</modal>
Hello{{name}
你的头衔在这里
您的html内容在这里


请参阅本文中的详细信息

使用
@Input
@Output
以及如何获取其他组件的html?请给我更多的细节。检查这个:@echonax它有帮助me@A.Gladkiy酷:-)使用
@Input
@Output
以及如何获取其他组件的html?请给我更多的细节。检查这个:@echonax它有帮助me@A.Gladkiy酷:-)