使用@input和@output在角度分量之间传输数据 [英] Transfer data between angular components using @input and @output

查看:77
本文介绍了使用@input和@output在角度分量之间传输数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个组成部分,相互依存.

I have two components sitting one in another.

    settings folder
      |--settings.component.css
      |--settings.component.html
      |--settings.component.ts
      |-- userPRofile folder
            |-- userProfile.component.css
            |-- userProfile.component.html
            |-- userProfile.component.ts

现在在设置组件中,我在OnInit期间获得了一些具有功能的数据.

Now in settings component, I get some data with function while OnInit.

    this.service.getUserSettings().subscribe(
       res => {
         this.userSettings = res;

现在我希望将此数据发送到userProfile组件.我怎样才能做到这一点?

And now I want this data to be sent to the userProfile component. How can I achieve this?

推荐答案

您只需要使用属性绑定将数据传递给子组件

you just need use property binding to pass the data to child component

设置组件模板

<app-user-profile [data]="userSettings"></app-user-profile>

userProfile.ts

@Input() data:any;

现在, userSettings 中的值将传递给 data 属性.

now the value from the userSettings will pass to the data property.

这篇关于使用@input和@output在角度分量之间传输数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆