【问题标题】:custom property event input() value not displaying自定义属性事件输入()值​​未显示
【发布时间】:2018-11-12 21:16:52
【问题描述】:

下面是我的父组件代码。我正在尝试从中获取数据 自定义绑定组件到应用组件。但我无法得到 来自父组件的值。我的父组件是 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


【解决方案1】:

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

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

【讨论】:

  • 好-快乐的编码:)
【解决方案2】:

App-root 组件必须是根组件。所以这应该是顶级组件。一切都在该组件内部,而不是相反。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 2011-03-02
    • 2016-03-21
    • 2020-07-05
    • 2014-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多