子component中的html文件

<button (click)="Send()">送出</button><br>

子component中的ts文件

import { Component, OnInit, Output } from '@angular/core';
import { EventEmitter } from '@angular/core'; @Component({
selector: 'app-todo-input',
templateUrl: './todo-input.component.html',
styleUrls: ['./todo-input.component.css']
})
export class TodoInputComponent implements OnInit {
public content: string;
@Output() onSend: EventEmitter<string> = new EventEmitter<string>();
constructor() { } ngOnInit(): void {
this.content = "Hello";
} Send(){
this.onSend.emit(this.content);
}
}

父component中的html

<app-todo-input (onSend)="onSend($event)"></app-todo-input>

父component中的ts

import { Component, OnInit } from '@angular/core';
import {Todo} from '../../models/todo' @Component({
selector: 'app-todo',
templateUrl: './todo.component.html',
styleUrls: ['./todo.component.css']
})
export class TodoComponent implements OnInit { public List:Todo[]=[]; constructor() { } ngOnInit(): void {
// this.List = [
// {id:1,content:'Test'},
// {id:2,content:'Test2'},
// {id:3,content:'Test3'},
// ];
}
onSend(content: string){
alert(content);
} }

												

最新文章

  1. 项目 &quot;Model&quot; 受源代码管理。向源代码管理注册此项目时出错。建议不要对此项目进行任何更改。
  2. 真机测试-Please enter a different string错误解决
  3. Redis在windows环境下的部署
  4. 正宗PC Unix实验环境
  5. 关于css3 中filter的各种特效
  6. SQL 刪除
  7. 让BOOTSTRAP默认SLIDER支持触屏设备
  8. StorSimple 简介
  9. Python Tutorial 学习(三)--An Informal Introduction to Python
  10. AES的S-BOX构造优化
  11. 负载均衡 &gt; 常见问题
  12. Android音频系统之AudioPolicyService
  13. Spring AOP分析(1) -- 基本概念
  14. 设计模式一: 单例模式(Singleton)
  15. .NET 内存分配笔记
  16. Android 开发 音视频从入门到提高 任务列表 转载
  17. JavaScript字符集
  18. ASP.NET MVC 常用路由总结
  19. Mac下的SecureCRT使用技巧
  20. Flyweight享元模式(结构型模式)

热门文章

  1. analysis_screencap
  2. std::string类详解
  3. js 组合继承详解
  4. loto仪器_如何模拟输出凸轮轴和曲轴波形_用任意波形信号源SIG852?
  5. ELK集群之kafka(7)
  6. Git+windows安装教程(一)
  7. APP 自动化之appium元素定位(三)
  8. Unity——技能系统(一)
  9. php 递推 递归
  10. Three.js实现脸书元宇宙3D动态Logo