博客
关于我
Angular开发(六)-关于组件之间的数据交互
阅读量:143 次
发布时间:2019-02-26

本文共 2521 字,大约阅读时间需要 8 分钟。

? Angular ????????????????????????????????????

???????????????

??????????????????????????????????????????????????????

??? HTML:

  • { {item.name}}----{ {i+1}}--{ {item.id}}
  • ??? TypeScript:

    dataSet = [  { id: 0, name: "??" },  { id: 1, name: "??" },  { id: 2, name: "??" }];bar(event: any) {  console.log(event);}

    ??? HTML:

    ??? TypeScript:

    @Input() names: any = {};@Output() foo = new EventEmitter
    ();todo(event: any) { this.foo.emit('??');}

    ????? emit ??????????????????????????????

    ???????????????

    ? Angular ???????????????????????

    ??? HTML:

  • ??? TypeScript:

    dataSet = [  { id: 0, name: "??" },  { id: 1, name: "??" }];

    ??? TypeScript:

    @Input() names: any = {};childFn() {  console.log("???????");}

    ?? #father ?????????????????????

    ???? @ViewChild ???????

    ??????????????????????????????

    ??? TypeScript:

    @ViewChild(ChildComponent) child: ChildComponent;father() {  this.child.childFn();}

    ??? HTML:

  • ?????????

    ????????????????????????

    ??? TypeScript:

    private com1ToCom2: any;appFn(event: any) {  console.log(event);  this.com1ToCom2 = event;}

    ???? HTML:

    ??? TypeScript:

    @Input() com2: string = "";

    ???????????

    ????? Angular ?????????????????????

    ??? TypeScript:

    import { Component, OnInit } from '@angular/core';@Component({  selector: 'app-father1',  templateUrl: './father1.component.html',  styleUrls: ['./father1.component.css']})export class Father1Component implements OnInit {  public name: string = "????????";  public dataSet: any[] = [    { id: "0", name: "??" },    { id: "1", name: "??" },    { id: "2", name: "??" }  ];  constructor() {}  ngOnInit() {}}

    ??? TypeScript:

    import { Component, OnInit } from '@angular/core';import { Father1Component } from "app/father1/father1.component";@Component({  selector: 'app-child1',  templateUrl: './child1.component.html',  styleUrls: ['./child1.component.css']})export class Child1Component implements OnInit {  constructor(private father1: Father1Component) {}  ngOnInit() {}}

    ??? HTML:

    { father1.name }

    • { item.name }

    ??????

    ? Angular ?????????????????????? set ??????????

    ??? HTML:

    ??? TypeScript:

    import { Component, OnInit } from '@angular/core';@Component({  selector: 'app-comdemo01',  templateUrl: './comdemo01.component.html'})export class Comdemo01Component implements OnInit {  _input: string;  @Input() public set input(v: string) {    this._input = v.toUpperCase();    console.log(v);  }  public get input(): string {    return this._input;  }  constructor() {}  ngOnInit() {}}

    ??? HTML:

    I am fron { input }

    转载地址:http://vpvf.baihongyu.com/

    你可能感兴趣的文章
    NPOI初级教程
    查看>>
    NPOI利用多任务模式分批写入多个Excel
    查看>>
    NPOI在Excel中插入图片
    查看>>
    NPOI将某个程序段耗时插入Excel
    查看>>
    NPOI格式设置
    查看>>
    NPOI设置单元格格式
    查看>>
    Npp删除选中行的Macro录制方式
    查看>>
    NR,NF,FNR
    查看>>
    nrf24l01+arduino
    查看>>
    nrf开发笔记一开发软件
    查看>>
    nrm —— 快速切换 NPM 源 (附带测速功能)
    查看>>
    nrm报错 [ERR_INVALID_ARG_TYPE]
    查看>>
    NS3 IP首部校验和
    查看>>
    NSDateFormatter的替代方法
    查看>>
    NSError 的使用方法
    查看>>
    NSGA-Ⅲ源代码
    查看>>
    nsis 安装脚本示例(转)
    查看>>
    NSJSON的用法(oc系统自带的解析方法)
    查看>>
    nslookup 的基本知识与命令详解
    查看>>
    NSNumber与NSInteger的区别 -bei
    查看>>