2つのテキストボックスがあります。 1つのテキストボックスはユーザーからの生年月日を受け取り、生年月日に基づいて計算し、別のテキストボックスに年齢を表示します。生年月日から年齢をタイプ2を使って計算するには
ここに私のコンポーネントクラスが
Student.component.html
<div class="row">
<div class="input-field col m2">
<input type="date" id="txtdate">
</div>
<div class="input-field col m4">
<input type="number" id="age">
</div>
student.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'stud',
templateUrl: './student.component.html'
})
export class StudentComponent implements OnInit
{
constructor() { }
ngOnInit() { }
}
function CalculateAge()
{
var birthdate = <HTMLElement>document.getElementById("txtdate");
var dt = new Date();
var today = dt.getDate();
}
私はどのようにcalculatんです生年月日からの年齢?
のvalueOfを使用してみてください:VAR差= today.valueOf() - birthdate.valueOf(); – darron614