• angular父子组件传值


    angular 组件传值---****---子传父。。。。@Output
    *****子组件
    --------ts文件
    import {Component, Output, EventEmitter,OnInit} from '@angular/core';
    @Component({
    selector: 'child-Component',
    templateUrl: './child.component.html',
    styleUrls: ['./child.component.less']
    })
    export class childComponent implements OnInit {
    //使用"事件传递"是 "子组件" 向 "父组件" 传递数据最常用的方式,子组件需要实例化EventEmitter类来订阅和触发自定义事件
    @Output() childDataevent = new EventEmitter();//自定义事件 实例化EventEmitter,赋值给event,event被@Output装饰器定义为输出属性,
    private username: string; // 这样event具备了向上级传递数据的能力,通过调用EventEmitter类中定义的emit方法,来向上传递数据

    constructor() {}
    ngOnInit(): void {}
    submitVal(){
    this.childDataevent.emit(this.username);
    return
    }
    }
    -----html文件
    用户名<input nz-input [(ngModel)]="username" name="username" type="text">
    <button (click)="submitVal()">提交--子传父</button>
    *****父组件
    --------ts文件
    import { Component, OnInit } from '@angular/core';
    @Component({
    selector: 'logoSing',
    templateUrl: './logoSing.html',
    styleUrls: ['./logoSing.css']
    })
    export class LogoSingComponent implements OnInit {
    private parent_username: string;
    constructor() { }
    ngOnInit() { }
    getData(event) {
    this.parent_username = event;
    }
    }
    --------html文件
    子组件展示在父组件的值:{{parent_username}}
    <child-Component (childDataevent)="getData($event)"></child-Component>

    angular 组件传值---****---父传子。。。。@Input


    *****父组件

    ********子组件

    *******父html

    *****子组件

  • 相关阅读:
    Python第二
    Python第一讲以及计算机基础
    MySQL第五讲
    MySQL第四讲
    MySQL第三讲
    MySQL第一讲概论
    MySQL日常笔记第二讲
    Linux修改用户组
    XAMPP中proftpd的简明配置方法
    解决php configure: error: Cannot find ldap libraries in /usr/lib.错误
  • 原文地址:https://www.cnblogs.com/lihong-123/p/9987316.html
Copyright © 2020-2023  润新知