首页 > 解决方案 > 自定义属性事件输入()值​​未显示

问题描述

下面是我的父组件代码。我正在尝试将数据从 customebinding 组件获取到应用程序组件。但我无法从父组件中获取值。我的父组件是customebinding,子组件是appcomponent。

import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-customebinding',
templateUrl: './customebinding.component.html',
styleUrls: ['./customebinding.component.scss']
})
export class CustomebindingComponent implements OnInit {
name="ramu";
constructor() { }
ngOnInit() {
}
}
html code is
<app-root [recieveName]="name"></app-root>

下面是我的子组件。

    @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
    })
    export class AppComponent {
    @Input() recieveName:string;
    }
html code is
recieve name is {{ recieveName }}

任何人都可以告诉我错误在哪里。

标签: angular

解决方案


如果您正在引导尝试交换子和父关系并绑定属性,则您AppComponent不能成为子组件AppComponent@Input()

希望这会有所帮助 - 编码快乐 :)


推荐阅读