how to pass value to input time tag using ng-model
NickName:RohanSalins Ask DateTime:2019-07-09T19:55:59

how to pass value to input time tag using ng-model

Hi i am trying to pass value to a input time tag, from javascript - angular JS. Here is the following code.

JS :

$scope.from="09:00:00"
$scope.from="17:00:00"

HTML :

From : <input type="time" ng-model="from" > 
To : <input type="time" ng-model="to" >

No value is getting updated inside input element. what is the mistake in above code?

Here is the Full code :

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

From: <input type="time" ng-model="fromTime"><br>
To: <input type="time" ng-model="toTime"><br>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.fromTime="09:00:00";
    $scope.toTime="17:00:00";
});
</script>

</body>
</html>

Error: [ngModel:datefmt]

Copyright Notice:Content Author:「RohanSalins」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/56952041/how-to-pass-value-to-input-time-tag-using-ng-model

Answers
Bill P 2019-07-09T12:22:42

After angularjs version 1.3, all date related inputs require a model of type Date().\ndocumentation\n\nSo you need to change the values to Date objects like this e.g. :\n\n$scope.from= new Date(1970, 0, 1, 09, 0, 0);\n$scope.to= new Date(1970, 0, 1, 17, 0, 0);\n\n\nCheck the demo: fiddle",


More about “how to pass value to input time tag using ng-model” related questions

how to pass value to input time tag using ng-model

Hi i am trying to pass value to a input time tag, from javascript - angular JS. Here is the following code. JS : $scope.from="09:00:00" $scope.from="17:00:00" HTML : From : &lt;input typ

Show Detail

ng-model value as a minimum value in a time input

It is possible using angularjs to put a ng-model value as a minimum value in a time-type input? I try this. &lt;input type="text" ng-model="valueHour" name="valueHour" value="valueHour"&gt; &

Show Detail

How to value pass option to input ng-model

&lt;div ng-app ng-controller="MyCtrl"&gt; &lt;select ng-model="referral.organization" ng-options="b for b in organizations"&gt;&lt;/select&gt; &lt;/div&gt; &lt;script t

Show Detail

Cant pass value to controller with ng-model or format date in input tag

I am trying to format the date in my input tag and pass the date selected to the controller. Here is my code so far: &lt;input ng-if="shutDown" type="date" ng-model="dates" &gt; &lt;button...

Show Detail

How to bind data in input-tag using Angular JS

I am trying to bind data in input_tag using following code: &lt;label class="item item-input"&gt; &lt;input type="text" placeholder="Title" ng-model="item.Title" minleng

Show Detail

Angular ng-model issue on time input

I'm having an issue using ng-model with time input on my app. I've searched around and couldn't find any other questions regarding this but I may be mistaken. I have time inputs with ng-model and am

Show Detail

Pass a li tag value to a text input

hi I have a li tag as follows: &lt;li value="myLi" class="myLi"&gt;My element&lt;/li&gt; I tried this jquery code: $(".myLi").click(function(){ document.getElementById(&q

Show Detail

Dynamically change name of ng-model in html tag

I want to change my ng-model name (in the html input tag) for each input tag dynamically. For example if my json file looks like: [{cows: 0, pigs: 14, roosters: 2, horses: 23, goats: 21}] and I am

Show Detail

AngularJS - Select tag's ng-model value not showing up

I am using AngularJS. I have a select tag. The tag's value is bound by ng-model. The ng-model variable has a value (coming from server). That value does not show up in the select dropdown tag. It s...

Show Detail

Angular using ng-model in input field get null

I know how to pass a value from a view to a controller using ng-model. In the controller it just gets the value from the view using this code $scope.name = this.ngmodelnameinview. Is it compulso...

Show Detail