我有一个指令来初始化DOM元素上的jQueryUI排序表.jQueryUI排序表还有一组回调事件,在某些操作上触发.例如,当您 Select start或stop个排序元素时.
我希望通过emit()
函数传递此类事件的返回参数,这样我就可以实际看到回调函数中发生了什么.我只是还没找到通过EventEmiiter
传递参数的方法.
我目前有以下几点.
我的指示:
@Directive({
selector: '[sortable]'
})
export class Sortable {
@Output() stopSort = new EventEmitter();
constructor(el: ElementRef) {
console.log('directive');
var options = {
stop: (event, ui) => {
this.stopSort.emit(); // How to pass the params event and ui...?
}
};
$(el.nativeElement).sortable(options).disableSelection();
}
}
这是my Component
,它使用了指令指定的事件:
@Component({
selector: 'my-app',
directives: [Sortable],
providers: [],
template: `
<div>
<h2>Event from jQueryUI to Component demo</h2>
<ul id="sortable" sortable (stopSort)="stopSort(event, ui)">
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 1</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 2</li>
<li class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>Item 3</li>
</ul>
</div>
`
})
export class App {
constructor() {
}
stopSort(event, ui) { // How do I get the 'event' and 'ui' params here?
console.log('STOP SORT!', event);
}
}
如何获取stopSort()
函数中的event
和ui
参数?