angular - 自定义属性事件输入()值未显示
问题描述
下面是我的父组件代码。我正在尝试将数据从 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 }}
任何人都可以告诉我错误在哪里。
解决方案
如果您正在引导尝试交换子和父关系并绑定属性,则您AppComponent
不能成为子组件AppComponent
@Input()
希望这会有所帮助 - 编码快乐 :)
推荐阅读
- r - 在 dplyr 管道期间添加 rnorm 但在设置 sd 时按组设置它
- rust - rust bindgen unaligned tcache chunk 错误
- javascript - 基于类添加弹出窗口(最有可能)
- php - 带前导零的格式数字
- javascript - 导入模块时出现意外的令牌 {
- r - 在 R 中绘制全局投影栅格
- node.js - MQTT 消息事件中的异步函数
- python - 脚本不更改 json 值
- c# - 将匿名用户或错误的用户类型重定向到 ASP.net MVC 3 中特定控制器内的登录页面
- ruby-on-rails - has_many 通过关系的 ActiveRecord "where" 子句