Int*_*eep 2 components typescript angular
我的目标是将字符串参数传递给组件。示例:我有一个组件可以保存并显示标题和副标题。我想在设置选择器时传递这些字符串。就像是:
@Component({
selector: 'title-subtitle',
})
Run Code Online (Sandbox Code Playgroud)
在 html 中:
<title-subtitle title="My title" subtitle="My subtitle"></title-subtitle>
Run Code Online (Sandbox Code Playgroud)
要使用 @input 将字符串从父组件传递到子组件,有两种方法。
如果你想传递字符串,
<child-component childInput="child input"> </child-component>
Run Code Online (Sandbox Code Playgroud)
如果要将变量从父组件传递给子组件,
<child-component [childInput]="parentInput"> </child-component>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7298 次 |
| 最近记录: |