首页 > 其他 > 详细

Angular中input和output使用

时间:2019-05-13 23:46:27      阅读:257      评论:0      收藏:0      [点我收藏+]
// 写法一: 
1 @Components({ 2 ...., 3 inputs:[‘init‘], 4 outputs:[‘finish‘] 5 }) 6 export class xxx(){ 7 okEvent: EventEmitter<any> = new EventEmitter(); 8 9 ok(){ 10 // this should match the type define in EventEmitter 11 this.okEvent.emit(‘the value want to pass‘); 12 } 13 } 14 15 // in another components 16 <ddd (finish)="finish($event)" [init]="value pass in"></ddd> 17 18 $event => will catch the return value

 1 // 另外一种写法:
 2 import { Component, View, Input, Output, EventEmitter } from ‘angular2/angular2‘;
 3 
 4 @Components({
 5      ....
 6 })
 7 export class xxx(){
 8   @Input() init;
 9   // @Output(alias name)
10   @Output(‘finish‘) okEvent:EventEmitter<Any> = new EventEmitter();
11 
12   
13   ok(){
14      // this should match the type define in EventEmitter if use typescript
15      this.okEvent.emit(‘the value want to pass‘);
16   }
17 }
18 
19 // in another components
20 <ddd (finish)="finish($event)" [init]="value pass in"></ddd>
21 
22 $event => will catch the return value

Angular中input和output使用

原文:https://www.cnblogs.com/szy-du/p/10859621.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!