How come my AngularJS ngModel is successfully binding to the time inputs, yet failing to bind to the date inputs?

I am facing an issue while trying to connect an input of type date to a model. Although I am successful in binding to time fields, I am encountering difficulties with date fields. Below is the HTML snippet:

<div ng-app ng-controller="HistoryCtrl">
    <input type="date" nm-model="startDate" />
    <input type="time" ng-model="startTime" />
    <input type="date" nm-model="endDate" />
    <input type="time" ng-model="endTime" />
    <button ng-click="updateForm()">Update</button>
</div>

This is a simplified version of my controller:

function HistoryCtrl($scope) {

    $scope.result = {
        result: 'success',
        start: '2013-11-23 03:00:00',
        end: '2013-11-24 16:30:00',
        delta: 0.05681799352169
    };

    $scope.updateForm = function () {
        $scope.updateTimespan($scope.result.start, $scope.result.end);
    };

    $scope.updateTimespan = function (start, end) {
        $scope.startDate = start.split(" ")[0];
        $scope.startTime = start.split(" ")[1];
        $scope.endDate = end.split(" ")[0];
        $scope.endTime = end.split(" ")[1];
    }
}

To view the behavior, check out this fiddle: http://jsfiddle.net/t3m6r/2/

Using Google Chrome 31.0.1650.57 for Mac, upon clicking the "Update" button, I observe that the time fields get updated but not the date fields. Could someone provide insights on why this might be happening? Am I maybe approaching it incorrectly?

Answer №1

Make sure to use the correct attribute "ng-model" instead of "nm-model".

<input type="date" ng-model="startDate" />
<input type="time" ng-model="startTime" />
<input type="date" ng-model="endDate" />
<input type="time" ng-model="endTime" />

For more information, check out this JS Fiddle

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A step-by-step guide on implementing lazy loading for a specific div section using either AJAX or Java

I'm facing an issue with a div section that contains numerous tables pulled from my database. The main problem here is that when the page loads, it takes a considerable amount of time to fully load all the content, causing a significant delay. Could ...

Ways to specifically load a script for Firefox browsers

How can I load a script file specifically for FireFox? For example: <script src="js/script.js"></script> <script src="js/scriptFF.js"></script> - is this only for Firefox?? UPDATE This is how I did it: <script> if($. ...

Ramjet: Unveiling the Magic of Making Elements Appear and Disappear

Currently, I am attempting to implement the code for ramjet from . However, I am facing an issue where element a does not disappear when transitioning into b. Additionally, I am encountering an error message "--Uncaught TypeError: Cannot read property &apo ...

Utilize Mongo's $facet feature to retrieve and calculate the number of tags associated with the products that have been

My current aggregation pipeline looks like this: aggregate.lookup({ from: 'tags', localField: 'tags', foreignField: '_id', as: 'tags' }); aggregate.match({ productType: 'prod ...

Hold off on creating the directive until the page has fully loaded and is operating smoothly

I'm currently developing a one-page application, but I'm facing performance issues with certain parts that are running too slow. The sluggishness is mainly due to the fact that I'm displaying 400 complex elements in a repeater for users to s ...

What could be the reason for the unexpected undefined value of my ajaxurl variable?

Seeking assistance with implementing code to track mp3 plays in a Wordpress plugin using ajax-counter.js jQuery(document).ready(function($) { console.log(ChurchAdminAjax.ajaxurl); $("audio").bind("play", function(){ console.log(ChurchAdmin ...

Difficulty paginating jqgrid when using an array as the data source

Encountering an issue with pagination in jqgrid while working with array data containing 18 records. Even after specifying pagination:true, pager:jQuery('#pager1'), the records are not displaying in pages. Can anyone assist me in implementing pag ...

`How can I fetch external JSON data using an AJAX request in an HTML document?`

Testing the functionality of this HTML page by creating a dummy JSON file, but encountering an issue with loading the data via AJAX request. The specific error message received is: Uncaught ReferenceError: data is not defined. Struggling to call and in ...

Ways to add elements to the DOM using jQuery from the local storage?

I'm facing a challenge where I have an input field and store the inputs in local storage. When I click on 'add', I want to immediately append the new inputs to my ul element. However, simply appending the current input won't work as it ...

Forcing an iframe in an ASP.NET web application to refresh and reload

Although I have experience in .NET Core development, ASP.NET Web Apps are new territory for me. Within my Index.cshtml, there is an iframe with the following attributes: <iframe height="800" width="1300" loa ...

The setState function in the useState hook is being called only one time when triggered by an EventListener

Within my functional component, I am utilizing the useState hook to store state. When the user reaches the bottom of the page, I want to dynamically add content. To achieve this, I implemented an EventListener for 'scroll' within a useEffect hook ...

The rendering of graphs in FusionCharts is experiencing delays particularly in Internet Explorer, with Chrome performing more efficiently in comparison

I am currently utilizing FusionCharts to generate and display graphs. My requirement is to load over 60 graphs on a single page. Upon testing the page loading in Internet Explorer 11, it is taking approximately 5 minutes. However, when using Google Chrom ...

Utilizing JavaScript regex to eliminate multiple backslashes while maintaining the special character

To load JSON data with multiple backslashes before a newline character, we are utilizing JavaScript. An example of this is: { "test": { "title": "line 1\\\\\\\nline2" } } Various RegEx patterns have been ...

AngularJS is having trouble parsing JSON data accurately

I have developed an application that utilizes AngularJS HTTP Get method to read data from a JSON file. However, I am encountering an issue where the expected results are not being displayed in the table. Below is the code snippet: HomeController using S ...

Why isn't the background-image displaying with the use of the url() function?

I've been attempting to set an image as the background using background-img:url(imageLing), but it's not working properly. When I inspect the element, it shows me background-image: url(assets/backgrounds/5.jpg);. What could be causing this issue? ...

transmitting JSON information and retrieving it again

I am currently navigating the process of passing objects through AJAX, and I find myself struggling with debugging as I am uncertain about both the passing and retrieving aspects. Essentially, my dilemma lies in making an AJAX request to a PHP controller ...

What is the best way to seamlessly move an element from a margin-left position of -9999px back onto the page?

Here are some additional details - because of unusual restrictions with the YouTube API, I have to push a container off the page in order to create the illusion that the container is hidden. I accomplish this using the following CSS class: .my_hide{ ...

The <form> element is giving me headaches in my JavaScript code

Trying to troubleshoot why my HTML pages render twice when I add a form with JavaScript. It seems like the page displays once with the script and again without it. Below is the basic HTML code: <form action="test.php" method="post"> <div class=" ...

Using rowspan to display JSON data in AngularJS

Unique Json data: [{ cityName: Seattle, population: 1000000, rank: 1 }, { cityName: Portland, population: 800000, rank: 2 }, { cityName: San Francisco, population: 900000, rank: 3 }, { cityName: Los Ange ...

"What is the best way to retrieve the value of an HTML input in

I am looking to store a variable that can be retrieved from JavaScript and then utilized in PHP upon form submission. For this purpose, I have added an input field in the HTML code: HTML <input type="hidden" name="videoname_var" id="videoname_var" me ...