我的 App Component.html 有一个基本的导航和一个日期选择器,就像这样......
<div class="container-fluid">
<div class="row">
<!-- Navigation Removed -->
<div class="col-md-2 float-right">
<kendo-datepicker
(valueChange)="onChange($event)"
[(value)]="value">
</kendo-datepicker>
</div>
</div>
</div>
<router-outlet></router-outlet>
component.ts 的设置方式如下:
import { Component, ViewEncapsulation, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-root',
encapsulation: ViewEncapsulation.None,
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
@Input() value: Date = new Date();
@Output() dateChanged: EventEmitter<Date> = new EventEmitter<Date>();
constructor() {}
public onChange(value: Date): void {
this.dateChanged.emit(value);
}
}
我有一些页面有一个调用服务的网格控件,但是日期当前是硬编码的,这一切都很好。我希望能够根据从上述日期选择器中选择的日期刷新网格数据,本质上,我将单击数据选择器,发出的值将通过网格控制器传递给组件中的方法。
带网格的控制器:
import { Component, OnInit, Input } from '@angular/core';
import { GridDataResult, DataStateChangeEvent } from '@progress/kendo-angular-grid';
import { DataSourceRequestState } from '@progress/kendo-data-query';
import { DataService } from '../services/DataService.service';
import { Observable } from 'rxjs/Observable';
import { State } from '@progress/kendo-data-query';
@Component({
templateUrl: './grid.component.html',
styleUrls: ['./grid.component.css']
})
export class GridComponent implements OnInit {
public products: GridDataResult;
public state: DataSourceRequestState = {
skip: 0,
take: 25
};
@Input() value: Date = new Date();
constructor(private dataService: DataService) { }
ngOnInit() {
this.dataService.fetch(this.state).subscribe(r => this.products = r);
}
public dataStateChange(state: DataStateChangeEvent): void {
this.state = state;
this.dataService.fetch(state)
.subscribe(r => this.products = r);
}
}