Angular父组件调用子组件里面的方法
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父组件调用子组件里面的方法相关推荐
- angular父组件调用子组件方法
angular 父组件调用子组件方法 父组件TS代码: <app-son #datepicker></app-son> @ViewChild('datepicker') dat ...
- Vue父组件调用子组件的方法并传参的两种方式(用$refs.refName.functionName、window.function)
如需了解儿子怎么控制老子的,传送门:https://s-z-q.blog.csdn.net/article/details/120094689 父组件father.vue <template&g ...
- vue父组件调用子组件的方法
vue组件与组件通信有如下几种情况: 平行组件 父组件与子组件 子组件与父组件 它们之间通信有几种方法有: props 自定义事件 vuex 今天我们聊一下父组件调用子组件的一种方法 parent.v ...
- Vue中父组件调用子组件的方法
场景 SpringBoot+Vue+Echarts实现选择时间范围内数据加载显示柱状图: SpringBoot+Vue+Echarts实现选择时间范围内数据加载显示柱状图_BADAO_LIUMANG_ ...
- vue 父组件调用子组件内置方法
背景介绍:外派到泰康做项目.这个项目中有个选择组织的功能,是一个树桩结构的懒加载,于是我就element-ui的tree组件封装了一个公共的组件. 但是后来发现他们的公司组织结构不是都请求的同一个接口 ...
- 【VUE实战问题记录】Vue 父组件调用子组件的使用方法
Vue前端项目父组件调用子组件的时候,调用方式如下: 父组件 <template><div><child ref="refChild">< ...
- vue中组件之间调用方法——子组件调用父组件的方法 父组件调用子组件的方法
vue中组件之间调用方法--子组件调用父组件的方法 & 父组件调用子组件的方法 1.vue中子组件调用父组件的方法 1.1.第一种方法是直接在子组件中通过this.$parent.event来 ...
- vue3 setup语法糖下父组件调用子组件的方法
vue3下,父组件调用子组件的方法,如果使用了<script setup> 这种写法,那么子组件方法需要采用defineExpose()进行修饰,才能被外界调用.上代码: 1.子组件 _p ...
- react 父组件调用子组件方法--通过 props 实现
父组件中 // 引入子组件 import GlobalTable from '../globalComponents/global-table'export default class Assuran ...
最新文章
- 2022-2028年中国高纯铜市场研究及前瞻分析报告
- ORB-SLAM中的ORB特征(提取)
- 使用vue.js路由踩到的一个坑Unknown custom element
- oneshot单样本学习笔记
- python豆瓣爬虫爬取评论做成词云
- conscience ['kɔnʃəns]
- Tomcat学习笔记01【Web相关概念、Tomcat基本操作】
- java volatile 原子性_Java中volatile不能保证原子性的证明
- python 抓取百度音乐
- 线性规划的标准型与规范型 (Standard and Canonical Forms)
- 2017二级c语言题库贴吧,2017二级c语言题库
- STC系列单片机烧录
- 腾讯云服务器搭建鸿蒙Hi3861开发板开发环境
- 威金又现!专杀收集整合
- PHP中使用gRPC客户端
- python计算实例_python实例: 税率计算
- [AHK]按住左键可以移动鼠标下的窗口
- 英国内政部(Home Office)间谍机构(spy powers)假装它是Ofcom咨询中的一名私人公民1525446087967...
- 解决新电脑开机无法跳过联网(找不到网络控制流进程)
- 录屏软件哪个好用?10个免费好用的「录屏软件」推荐