2017-11-13 1 views
0

私はanglejsのアプリケーションのための簡単なフォームを作成しています。 「mm:ss」の形式で分と秒だけで時刻データを受け取るための入力フィールドが必要です。これに取り組んだ人なら、あなたの援助は高く評価されます。私はすでに私のフォームの入力を作成しています。実際、私は他のプログラマーが作成したプロジェクトに取り組んでいます。次のように時間の入力のためのモデルが初期化されました:anglejsの形式(mm:ss)で分と秒をキャプチャするための入力

function initDate(date, indexX, indexY){ 
     if(date != null && date != ''){ 
     var dateArray = date.split(":"); 
     var dt = new Date(1970,1,1,dateArray[0],dateArray[1],dateArray[2]); 
     vm.modelDate[indexX][indexY] = dt; 
     } 
} 

<input name="inputExTime{{q.listSubQuestions[contTime].questionId}}{{contTime}}0" 
    type="time" class="form-control btn-act btn-act-inputs intime_ex" step="1" 
    ng-disabled="disabledfields" 
    ng-model="vm.modelDate[0][contTime]" 
    min="00:00:00" max="12:59:00" 
    ng-change="vm.changeDate(parentIndex,0,contTime);vm.calculateHours(form['inputExTime'+q.listSubQuestions[contTime].questionId+contTime+0].$modelValue, form['inputExTime'+q.listSubQuestions[contTime].questionId+contTime+2].$modelValue, form['inputExTime'+q.listSubQuestions[contTime].questionId+contTime+3], contTime);vm.average();" 
    ng-required="$index<vm.numberOfRequiredRows?(q.attributes.required==false?false:isregister):false" 
    ng-class="{true: 'inp-f'}[form['inputExTime'+q.listSubQuestions[contTime].questionId+contTime+0].$invalid]" 
    ng-init="vm.modelDate[0][contTime]=null;vm.initArray(''+q.listSubQuestions[contTime].questionId+contTime+0);vm.initDate(q.listSubQuestions[0].listAnswers[contTime].detail, 0, contTime);" 

/>

あなたが時間 timeのフォームで input要素を定義する必要が

答えて

0

<input type="time" ng-model="timeModel"> 

ng-modelは次のようになりDateオブジェクトです。それ以外の場合、AngularJSはエラーをスローします。 official documentation

var app = angular.module('time', []); 
 

 
app.controller('MainCtrl', function($scope) { 
 
    // The order of the params is the following: 
 
    // Year, Month, Day, Time, Minutes, Seconds 
 
    $scope.timeModel = new Date(2017, 10, 13, 10, 30, 0); 
 
});
<!DOCTYPE html> 
 
<html ng-app="time"> 
 

 
<head> 
 
    <meta charset="utf-8" /> 
 
    <title>Time Model Example using AngularJS</title> 
 
    <script> 
 
    document.write('<base href="' + document.location + '" />'); 
 
    </script> 
 
    <script data-require="[email protected]" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script> 
 
    <script src="app.js"></script> 
 
</head> 
 

 
<body ng-controller="MainCtrl"> 
 
    <input type="time" ng-model="timeModel"> 
 
</body> 
 

 
</html>

、あなたはこれについての詳細な情報を見つけることができます。

Keep Rocking!

+0

ありがとうございましたジョナサン、問題に関連するいくつかの詳細を追加しました。あなたが投稿したスニペットと同様の結果を得る方法について、より多くの情報を共有することができます。 –

関連する問題