Questions tagged «event-delegation»

7
委托:EventEmitter或可观察到的Angular
我正在尝试在Angular中实现类似委托模式的功能。当用户单击时nav-item,我想调用一个函数,该函数然后发出一个事件,而该事件又应由侦听该事件的其他某些组件处理。 这是场景:我有一个Navigation组件: import {Component, Output, EventEmitter} from 'angular2/core'; @Component({ // other properties left out for brevity events : ['navchange'], template:` <div class="nav-item" (click)="selectedNavItem(1)"></div> ` }) export class Navigation { @Output() navchange: EventEmitter<number> = new EventEmitter(); selectedNavItem(item: number) { console.log('selected nav item ' + item); this.navchange.emit(item) } } 这是观察部分: export class …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.