0

생년월일 필드와 나이 텍스트 상자가 있습니다. angularJs에서 생년월일을 선택할 때 나이 텍스트 상자를 자동으로 업데이트 할 수 있습니까? 입력AngularJs : 생년월일이 자동으로 입력되는 경우

<label for="" class="col-md-2 control-label">Dob</label> 
    <input type="datepicker"class="form-control" my-date-picker required="required" ng-model="newItem.dob" /> 
    <label for="" class="col-md-2 control-label">Age</label> 
    <input type="text" class="form-control" disabled="true" ng-model="newItem.age" /> 
+3

당신이 이미 시도한 COE를 게시하시기 바랍니다 수 있습니까? – lucuma

+0

[가능한 두 날짜의 년 수를 계산하는 방법은 무엇입니까?] (http://stackoverflow.com/questions/8152426/how-can-i-calculate-the-number-of-years-betwen-two -dates) –

+0

@MikeRobinson. 각도가 0 인 솔루션이 필요합니다. –

답변

2

이런 식으로 뭔가에 대한 코드는 첫 번째 입력에 겨 변화를 추가 입력이 변경 될 때 함수를 호출합니다. 이 함수는 범위에서 선언해야합니다. 컨트롤러에서

<label for="" class="col-md-2 control-label">Dob</label> 
<input type="datepicker" ng-change='myAgeFunction()' class="form-control" my-date-picker required="required" ng-model="newItem.dob" /> 
<label for="" class="col-md-2 control-label">Age</label> 
<input type="text" class="form-control" disabled="true" ng-model="newItem.age" /> 

자바 스크립트 :

$scope.newItem = {dob: "00/00/0000", age: 0 } // your object which refers to ng-model 
$scope.myAgeFunction = function(){ //your function goes here 
    $scope.newItem.age = ... code to calculate age; // update the model 
} 
관련 문제