角度2触发路由器模块外部的模态打开

时间:2016-12-20 04:04:39

标签: angular angular2-routing

我想通过点击路由器插座内组件模板中的按钮来触发路由器插座外部组件模板中div的隐藏/显示:

app组件

`<div class="content col-md-10 container-fluid">   
    <company-add-form></company-add-form>
    <router-outlet></router-outlet>
</div>`

公司添加表单组件

`<div>
    <p>Make me showwwww</p>
    <button class="btn">Close</button>
</div>`

公司页面组件(将在路由器插座内部呈现)

`<div>
    <button class="btn">Open company add form</button>
</div>`

思想

  • 通常父子关系非常一致,但因为路由器插座介于两者之间,所以只能使用ViewChild。

1 个答案:

答案 0 :(得分:0)

您无法绑定路由器添加的组件。

您应该使用共享服务@angular/injectable查看component communication来获取@angular cookbook中的示例。