Angular父组件“作用域”子组件
创始人
2024-10-25 02:00:32
0

以下是一个使用Angular的父组件和子组件的示例代码:

父组件的HTML模板:

{{ title }}

父组件的JavaScript代码:

import { Component } from '@angular/core';

@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.css']
})
export class ParentComponent {
  title = '父组件';
  message = '这是来自父组件的消息';
}

子组件的HTML模板:

{{ message }}

子组件的JavaScript代码:

import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-child',
  templateUrl: './child.component.html',
  styleUrls: ['./child.component.css']
})
export class ChildComponent {
  @Input() message: string;
}

在这个示例中,父组件通过在子组件上使用[message]="message"属性绑定将消息传递给子组件。子组件使用@Input()装饰器来接收从父组件传递的消息,并在模板中显示出来。

相关内容

热门资讯

透视能赢!hhpoker德州透... 透视能赢!hhpoker德州透视挂(透视)多乐辅助在哪里可以下载(其实是真的辅助修改器)-哔哩哔哩1...
透视ai代打!智星德州可以透视... 透视ai代打!智星德州可以透视吗(透视)四川游戏家园破解版ios(竟然真的是有辅助安装)-哔哩哔哩1...
现有说明如下!wepoker安... 现有说明如下!wepoker安装教程(透视)雀姬辅助工具(本来真的是有辅助插件)-哔哩哔哩1、雀姬辅...
透视好友!wepoker私人局... 透视好友!wepoker私人局规律(透视)福建天天开心万能辅助(好像真的是有辅助安装)-哔哩哔哩1、...
透视透视!来玩德州破解器(透视... 透视透视!来玩德州破解器(透视)宝宝浙江辅助脚本(一贯是真的辅助安装)-哔哩哔哩小薇(辅助器软件下载...
此事迅速冲上热搜!aapoke... 此事迅速冲上热搜!aapoker怎么提高中牌率(透视)心悦俱乐部游戏辅助(果然真的是有辅助平台)-哔...
突发!aapoker怎么开辅助... 突发!aapoker怎么开辅助器(透视)新上游辅助器(竟然是真的辅助工具)-哔哩哔哩1、完成新上游辅...
有消息称!wepoker私人局... 有消息称!wepoker私人局外卦(透视)广丰510k辅助(本来是有辅助插件)-哔哩哔哩1)广丰51...
截至发稿!购买wepoker模... 截至发稿!购买wepoker模拟器(透视)福州天天开心辅助(真是有辅助神器)-哔哩哔哩1、超多福利:...
据文件显示!hhpoker的辅... 据文件显示!hhpoker的辅助是真的吗(透视)福建大玩家辅助下载(好像是真的辅助神器)-哔哩哔哩1...