child.component.ts

import { Component } from '@angular/core';@Component({selector: 'app-child',templateUrl: './child.component.html',styleUrls: ['./child.component.scss']
})
export class ChildComponent {// 子组件的方法alert(d: any) {alert(d);}}

app.component.ts

import { Component, ViewChild } from '@angular/core';
import { ChildComponent } from './com/child/child.component';@Component({selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.scss'],
})export class AppComponent {@ViewChild('child') child: ChildComponent | undefined;//获取子组件对象childAlert(text: any) {this.child?.alert(text);//父组件调用子组件的方法}
}

app.component.html

<app-child #child></app-child><button (click)="childAlert('调用子组件的方法')">调用子组件的方法</button>

Angular父组件调用子组件里面的方法相关推荐

  1. angular父组件调用子组件方法

    angular 父组件调用子组件方法 父组件TS代码: <app-son #datepicker></app-son> @ViewChild('datepicker') dat ...

  2. Vue父组件调用子组件的方法并传参的两种方式(用$refs.refName.functionName、window.function)

    如需了解儿子怎么控制老子的,传送门:https://s-z-q.blog.csdn.net/article/details/120094689 父组件father.vue <template&g ...

  3. vue父组件调用子组件的方法

    vue组件与组件通信有如下几种情况: 平行组件 父组件与子组件 子组件与父组件 它们之间通信有几种方法有: props 自定义事件 vuex 今天我们聊一下父组件调用子组件的一种方法 parent.v ...

  4. Vue中父组件调用子组件的方法

    场景 SpringBoot+Vue+Echarts实现选择时间范围内数据加载显示柱状图: SpringBoot+Vue+Echarts实现选择时间范围内数据加载显示柱状图_BADAO_LIUMANG_ ...

  5. vue 父组件调用子组件内置方法

    背景介绍:外派到泰康做项目.这个项目中有个选择组织的功能,是一个树桩结构的懒加载,于是我就element-ui的tree组件封装了一个公共的组件. 但是后来发现他们的公司组织结构不是都请求的同一个接口 ...

  6. 【VUE实战问题记录】Vue 父组件调用子组件的使用方法

    Vue前端项目父组件调用子组件的时候,调用方式如下: 父组件 <template><div><child ref="refChild">< ...

  7. vue中组件之间调用方法——子组件调用父组件的方法 父组件调用子组件的方法

    vue中组件之间调用方法--子组件调用父组件的方法 & 父组件调用子组件的方法 1.vue中子组件调用父组件的方法 1.1.第一种方法是直接在子组件中通过this.$parent.event来 ...

  8. vue3 setup语法糖下父组件调用子组件的方法

    vue3下,父组件调用子组件的方法,如果使用了<script setup> 这种写法,那么子组件方法需要采用defineExpose()进行修饰,才能被外界调用.上代码: 1.子组件 _p ...

  9. react 父组件调用子组件方法--通过 props 实现

    父组件中 // 引入子组件 import GlobalTable from '../globalComponents/global-table'export default class Assuran ...

最新文章

  1. 2022-2028年中国高纯铜市场研究及前瞻分析报告
  2. ORB-SLAM中的ORB特征(提取)
  3. 使用vue.js路由踩到的一个坑Unknown custom element
  4. oneshot单样本学习笔记
  5. python豆瓣爬虫爬取评论做成词云
  6. conscience ['kɔnʃəns]
  7. Tomcat学习笔记01【Web相关概念、Tomcat基本操作】
  8. java volatile 原子性_Java中volatile不能保证原子性的证明
  9. python 抓取百度音乐
  10. 线性规划的标准型与规范型 (Standard and Canonical Forms)
  11. 2017二级c语言题库贴吧,2017二级c语言题库
  12. STC系列单片机烧录
  13. 腾讯云服务器搭建鸿蒙Hi3861开发板开发环境
  14. 威金又现!专杀收集整合
  15. PHP中使用gRPC客户端
  16. python计算实例_python实例: 税率计算
  17. [AHK]按住左键可以移动鼠标下的窗口
  18. 英国内政部(Home Office)间谍机构(spy powers)假装它是Ofcom咨询中的一名私人公民1525446087967...
  19. 解决新电脑开机无法跳过联网(找不到网络控制流进程)
  20. 录屏软件哪个好用?10个免费好用的「录屏软件」推荐

热门文章

  1. 微信小程序开发——修改小程序显示名称
  2. less命令乱码_less命令
  3. 判断是否为base64
  4. uni-app跨域 和 Vue 跨域
  5. 什么是SOCKS5代理
  6. 虚拟机安装Ubuntu18.04系统
  7. iOS 滑动浏览图片 捏合缩小放大 音量线控
  8. 人脸识别基础(FaceNet)
  9. 设计模式(现在只总结了常用的8种)
  10. 如何重建被完全删除的EFI分区