博客
关于我
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/

    你可能感兴趣的文章
    nodejs中Express 路由统一设置缓存的小技巧
    查看>>
    Nodejs中的fs模块的使用
    查看>>
    nodejs包管理工具对比:npm、Yarn、cnpm、npx
    查看>>
    NodeJs单元测试之 API性能测试
    查看>>
    nodejs图片转换字节保存
    查看>>
    nodejs字符与字节之间的转换
    查看>>
    NodeJs学习笔记001--npm换源
    查看>>
    NodeJs学习笔记002--npm常用命令详解
    查看>>
    nodejs学习笔记一——nodejs安装
    查看>>
    NodeJS实现跨域的方法( 4种 )
    查看>>
    nodejs封装http请求
    查看>>
    nodejs常用组件
    查看>>
    nodejs开发公众号报错 40164,白名单配置找不到,竟然是这个原因
    查看>>
    Nodejs异步回调的处理方法总结
    查看>>
    NodeJS报错 Fatal error: ENOSPC: System limit for number of file watchers reached, watch ‘...path...‘
    查看>>
    Nodejs教程09:实现一个带接口请求的简单服务器
    查看>>
    nodejs服务端实现post请求
    查看>>
    nodejs框架,原理,组件,核心,跟npm和vue的关系
    查看>>
    Nodejs模块、自定义模块、CommonJs的概念和使用
    查看>>
    nodejs生成多层目录和生成文件的通用方法
    查看>>