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

@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent implements OnInit { constructor() { } ngOnInit() {
}
greeting(str: string) {
console.log(str);
} }
<p>
child works!
</p>
<app-child #child1></app-child>
<app-child #child2></app-child>
<button (click)="child2.greeting('child2的问候')">点我</button>
import { Component, ViewChild } from '@angular/core';
import { ChildComponent } from './child/child.component'; @Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent { @ViewChild('child1')
child1: ChildComponent; constructor() { }
// tslint:disable-next-line:use-life-cycle-interface
ngOnInit(): void {
this.child1.greeting('child1的问候');
}
}

angular 父组件调用子组件的更多相关文章

  1. 父组件调用子组件 viewChild

    父组件调用子组件 1.在子组件的ts中声明一个变量 public  lineout:any="你好,我是被父组件调用的子组件";  2.在父组件的html中写入 (引入子组件) & ...

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

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

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

    qwq  前两天看了下vue,父子组件方法的调用,怕忘记,所以做个小记录. 一.父组件调用子组件的方法 1.父组件 <template> <div id="rightmen ...

  4. vue+element ui项目总结点(四)零散细节概念巩固如vue父组件调用子组件的方法、拷贝数据、数组置空问题 等

    vue config下面的index.js配置host: '0.0.0.0',共享ip (假设你的电脑启动了这个服务我电脑一样可以启动)-------------------------------- ...

  5. react 父组件调用子组件方法

    import React from 'react'import '../page1/header.css'import { Table } from 'antd'import Child from ' ...

  6. vue父组件调用子组件方法、父组件向子组件传值、子组件向父组件传值

      一.父组件调用子组件方法 父组件代码  parent.vue <template> <div> <button @click="parentFun" ...

  7. vue:父子组件间通信,父组件调用子组件方法进行校验子组件的表单

    参考: ElementUI多个子组件表单的校验管理:https://www.jianshu.com/p/541d8b18cf95 Vue 子组件调用父组件方法总结:https://juejin.im/ ...

  8. vue中子组件调用父组件里面的数据和方法 父组件调用子组件的数据和方法

    1.子组件直接调用父组件的数据和方法 在父组件father,vue <template> <div> <!-- 父组件里面的数据 --> <p>父组件里 ...

  9. Vue3 父组件调用子组件的方法

    Vue3 父组件调用子组件的方法 // 父组件 <template> <div> 父页面 <son-com ref="sonRef"/> < ...

  10. React 父组件调用子组件的方法

    父组件调用子组件的方法 React v16.3.0 及以后版本使用 import React, {Component} from 'react'; export default class Paren ...

随机推荐

  1. python开发模块基础:time&random

    一,time模块 和时间有关系的我们就要用到时间模块.在使用模块之前,应该首先导入这个模块 常用方法1.(线程)推迟指定的时间运行.单位为秒. time.sleep(1) #括号内为整数 2.获取当前 ...

  2. rpm --import /etc/pki/rpm-gpg/RPM* 有什么用?

      今天用yum安装软件,遇到了Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL问题,为了加深印象,特别搜索了RPM-GPG-K ...

  3. python's twelth day for me

    闭包: 内层函数对外层函数的变量(非全局变量)的引用. python 遇到闭包,有一个机制,会开辟一个空间,将闭包中的全部变量放入其中.且不会随着函数的结束而关闭. 闭包的完美体现:装饰器. 打印函数 ...

  4. svn锁定问题解决

    问题描述: 今天遇到svn文件被某个人锁定,搞得全部人都不能提交更新. 解决方法一: 首先,先定位到工程目录下,然后使用如下命令查看是否有锁 find . | grep ".svn/lock ...

  5. CSS 透明

    filter:alpha(opacity=60);-moz-opacity:0.5;opacity: 0.5;

  6. Android开发笔记 TableLayout常用的属性介绍

    今天看了安卓简单控件的布局方式,大概有绝对.相对.表格.线性.帧式布局五种方式,表格布局里面的一些属性相对来说比较复杂,下面主要谈谈表格方式布局的一些属性   TableLayout经常用到的属性有: ...

  7. leetcode486

    public class Solution { public bool PredictTheWinner(int[] nums) { // int n = nums.Length; // int[,] ...

  8. delphi 天气预报

    天气预报 var astream : tmemorystream; sStream : TStringStream; jv : TJSONValue; begin astream := tmemory ...

  9. xml和configparser模块

    一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, 但至今很多传统公司如金融行业的很多系统的接口还主要是xml. xml的格式如下,就是通过 ...

  10. 一个jquery在不同浏览器下的兼容性问题。

    <div id ='pdiv' style='visibility:hidden;'> <div id='cdiv'>子元素</div> </div> ...