从日期选取器获取数据具体化



如何从具体化日期选择器中获取数据?

我正在尝试使用Angular 2数据绑定来获取数据,但它不起作用。

我与startDate的绑定永远不会被调用,它永远不会改变,它保持未定义状态。


日期内容.html

<form action="#">
  <div class="input-field">
    <input id="date_picker" type="date" class="datepicker" [(ngModel)]="startDate">
    <label for="date_picker">Start Date</label>
  </div>
</form>

DateStuff.ts

@Component({
    selector: "date-stuff",
    templateUrl: "./DateStuff.html"
})
export class DateStuff {
    private _startDate: string;
    public ngAfterViewInit(): void {
        $(".datepicker").pickadate({
            selectMonths: true, // Creates a dropdown to control month
            selectYears: 15 // Creates a dropdown of 15 years to control year
        });
    }
    public get startDate(): string {
        return this._startDate;
    }
    public set startDate(value: string) {
        this._startDate = value;
    }
}

我找到了解决方案。我希望使用Angular 2绑定,但我找到了jquery的方法。

let year: string = $('.datepicker').pickadate('picker').get('highlight', 'yyyy');
let day: string = $('.datepicker').pickadate('picker').get('highlight', 'dd');
let month: string = $('.datepicker').pickadate('picker').get('highlight', 'mm');

如果有人有一个更优雅的解决方案 Angular 2 ,那就太好了!

最新更新