Describe the ng-model for this specific JSON input array in AngularJS

Aim: The task at hand is to update the data in the following format:

"open_hours": [ // (Note that open_hours is an array).
      {
        "weekday": "mon",
        "opens_at": "09:00",
        "closes_at": "22:00"
      },
      {
        "weekday": "tue",
        "opens_at": "09:00",
        "closes_at": "22:00"
      }
  ]

within this controller.js:

$scope.days = ["sun","mon","tue","wed","thu","fri","sat"];

$scope.restaurant = {};
$scope.restaurant.open_hours = [];

This information needs to be presented in the following template using the angular-bootstrap-ui timePicker directive:

<div class="row">
      <div class="col-lg-12">
        <table class="table table-striped table-hover table-condensed">
          <tbody ng-repeat="day in days">
            <tr>
              <td>
                <input type="hidden" ng-model="restaurant.open_hours[day].weekday" ng-value="day"/>
                {{day}}
              </td>
              <td>
                Opens at <uib-timepicker ng-model="restaurant.open_hours[day].opens_at" show-meridian="false" show-spinners="false" minute-step="15"></uib-timepicker>
              </td>
              <td>
                Closes at <uib-timepicker ng-model="restaurant.open_hours[day].closes_at" show-meridian="false" show-spinners="false" minute-step="15"></uib-timepicker>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>

The challenge lies in implementing this. Despite multiple tries, I have not been successful.

Answer №1

In order to populate the timepicker, you must have a date object ready.

var time = new Date();
  time.setHours(9);
  time.setMinutes(0);
  var closeTime = new Date();
  closeTime.setHours(22);
  closeTime.setMinutes(0);
  $scope.restaurant = {
    "open_hours": [
  {
    "weekday": "mon",
    "opens_at": time,
    "closes_at": closeTime
  },
  {
    "weekday": "tue",
    "opens_at": time,
    "closes_at": closeTime
  }
]};

If you need an example, check out this codepen with a demo.

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

Retrieve a segment of text from a specific position within an array

Hello, I am new to C++ and seeking guidance on how to extract a single sentence from a paragraph stored in a string array. To clarify, let's assume myArray[2] represents the 3rd index of a string array containing multiple sentences separated by newlin ...

Discover a corresponding object within an array

I am currently dealing with an array of objects in Javascript where I need to verify if a certain value exists within any object and return the corresponding id. The issue arises when using the some() function as it only seems to match the first object. T ...

Efficient PHP login process enhanced by jQuery

After a user logs out on my website, they are redirected to the home page. However, if they navigate back in their browser, it still shows them as logged in (although logged in features don't work). I am considering implementing a solution where I us ...

Passing "this" to the context provider value in React

While experimenting with the useContext in a class component, I decided to create a basic React (Next.js) application. The app consists of a single button that invokes a function in the context to update the state and trigger a re-render of the home compon ...

Identifying changes in Android volume settings via Progressive Web App (PWA)

After creating a PWA with React, I generated a TWA .apk using pwabuilder.com. While having a muted video playing on my screen, I am looking for a way to unmute the video when the user presses the volume change buttons on their Android mobile device. Is th ...

Invoking middleware within another middleware

I was recently following along with a web development tutorial on YouTube where the instructor introduced two middlewares called verifyToken and verifyUser. `verifyToken` const verifyToken = (req, res, next) => { const token = req.cookies.access_token ...

What is the process for building an interactive quiz using JavaScript?

In the process of creating a quiz, I envision a user interface that presents questions in a "card" format. These questions will include simple yes/no inquiries and some multiple-choice options. As the user progresses through the quiz, their answers will de ...

Altering the DOM directly within the componentDidMount() lifecycle method without needing to use

In ReactJS, I am facing an issue while trying to manipulate the DOM in the componentDidMount() method. The problem lies in the fact that the DOM is not fully rendered at this point, requiring me to use a setTimeout function, which I find undesirable. Upon ...

Adjust the content of an iframe based on the size of the screen

Hi there, I'm currently facing an issue with an ad that can't be resized. The support team suggested using two different ads - one for mobile and one for desktop. The dimensions of the ads are 720 x 90 and 300 x 100. I would like the ad to automa ...

To trigger the action of any button in Ionic/Angular, I need to double-click

I am encountering an issue with an app that I developed using the Ionic framework. While the app works perfectly on Android devices, I am facing a peculiar situation on iOS. Every time I click a button in the Simulator or on an actual iOS device, I have t ...

Can CSS be used to create curved dashed lines?

Is it possible to achieve dashed lines similar to the ones highlighted in the images below using only CSS? I have a responsive web page built with Bootstrap, and I need the dashed lines to adjust accordingly when the window width changes. https://i.sstat ...

Iteratively traverse the object to establish connections between parent and child elements

I've been working on creating a recursive function with some guidance I received here: looping through an object (tree) recursively The goal is to traverse the object 'o' and generate a new one where each key is associated with its parents ...

What is the best way to transfer information between different pages in an HTML document?

I am facing a specific requirement where I must transfer form data from one HTML page to another HTML page. The process involves a total of 5 pages, with the user entering data in the following order: 1st page: Name 2nd page: Weight 3rd page: Height 4t ...

Parent window login portal

I have just started learning how to program web applications, so I am not familiar with all the technical terms yet. I want to create a login window that behaves like this: When a user clicks on the Login button, a window should pop up on the same page t ...

Navigate through the rows and columns of an HTML table by utilizing Javascript with webdriver, specifically for Protractor in a non-angular environment

I need help with iterating through rows and columns using Selenium Webdriver. I am currently using Protractor for a non-angular web page. I have some Java code that works with the WebElement class to get the number of links, but now I need to transition th ...

Accessing a Jhipster login and authentication mechanism through a mobile application

Are you wondering how to acquire a session cookie and the CSRF token from jhipster, and then effectively utilize them in your mobile app API calls using HTTP session authentication? In your JHipster configuration, you can find a .yo-rc.json file that is g ...

Guide to transforming an embed/nested FormGroup into FormData

Presenting my Form Group: this.storeGroup = this.fb.group({ _user: [''], name: ['', Validators.compose([Validators.required, Validators.maxLength(60)])], url_name: [''], desc: ['', Validators.compose([Valida ...

Could you please ensure that the animation activates upon hovering over the "a" element?

Utilizing bootstrap, I have created the following code. I am looking to add functionality that triggers an animation upon mouseover of an img or a element, and stops the animation upon mouseleave. .progress-bar { animation: pr 2s infinite; } @keyfr ...

Is there a way to retrieve a promise from a function that triggers a $http.get request in AngularJS?

Looking for a solution to modify this function: getX: function ($scope) { $http.get('/api/X/GetSelect') .success(function (data) { ... ... }) .error(function (data) { ...

JavaScript not properly rendering CSS styles

If I insert the following HTML statically, the CSS style is correctly applied. HTML: <li class="connector"> <a href="#"> <img src="css/images/temp/connector2.png" alt="" width="192" height="192"> <span class="sr-only"& ...