AngularJs Directive continuously returns undefined

Exploring angularjs directives for the first time has been quite a challenge. I can't seem to figure out why my directive isn't working properly as the scope.durationTimeInput always returns undefined no matter what I try.

(function () {
'use strict';

angular.module('BlurAdmin.theme')
    .directive('durationInput', durationInput);

/** @ngInject */
function durationInput($window) {
    var tpl = '<div class="duration_time_input"> \
          <input ng-model="duration_time.hours" type="number" class="hours" placeholder="00" min="0" max="3" step="1" style="width: 45px"> \
        <span class="duration-time-sep">:</span> \
        <input ng-model="duration_time.minutes" type="number"  class="minutes" placeholder="00" min="0" max="59" step="1" style="width: 45px"> \
        </div>';

    return {
        restrict: 'A',
        template: tpl,
        replace: true,
        scope: {
            durationTimeInput: '='
        },
        link: function (scope, element, attrs) {
            console.log(scope);
            console.log(scope.durationTimeInput);
            scope.$watch('durationTimeInput', function (newValue) {
                var duration = moment.duration(newValue, 'minutes');

                scope.duration_time = {
                    hours: duration.hours(),
                    minutes: duration.minutes(),

                }
            });

            scope.$watchCollection('duration_time', function (newTime, oldTime) {
                if(scope.duration_time.hours==0&&scope.duration_time.minutes==0){
                    scope.duration_time.minutes=1;

                }
                scope.lapTimeInput = moment.duration(newTime, 'minutes').asMinutes();

            });
        }
    };
}

})();

I use this directive with a div tag:

<div duration-input="myIndex.duration" id="scheduleDuration"></div>

The value of myIndex.duration is dynamic and based on user interaction.

Answer №1

Attempt

<div duration-input duration-time-input="myIndex.duration" id="scheduleDuration"></div>

Ensure to include duration-time-input based on the scope that has been established.

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

Add HTML content to a specific div according to the option selected in a drop-down menu

I am currently working on a project where I need a button to insert HTML content into a div based on the value selected in a select box. However, the functionality is not working as intended. Upon clicking the button, nothing happens. I am unsure of what t ...

Tips for troubleshooting an Angular error when no specific information is provided

I'm encountering an error `ERROR Error: "[object Object]" in my console and my app is displaying a white screen. Everything was working perfectly fine before, and I can't pinpoint any changes that may have caused this issue. The error appears to ...

Implementing React with multiple event listeners for a single click event

One of the challenges I'm facing is with a function called playerJoin() in my React app. This function is triggered when a specific button is clicked. It sends data to the server, which then checks if the information matches what is stored. If there i ...

The service worker is attempting to access outdated information from the cached script

Within my project, I implement the loading of JSON files asynchronously using import().then. At times, a situation arises where new content is accessible but has not yet been applied, causing the old cached script bundle to attempt loading the JSON files ...

Ways to allocate space evenly between components of the same size in React Native

As a beginner in Javascript and React-native, I have been experimenting with the technology to assess its viability for potential use in my current workplace. However, I have encountered some challenges with the user interface. To enhance my understanding ...

When attempting to access a static method in TypeScript, an error occurs indicating that the property 'users_index' does not exist on the type 'typeof UserApiController'

Just dipping my toes into TypeScript and attempting to invoke a function on a class. In file A: import userAPIController from "./controllers/customer/userAPIController"; userAPIController.users_index(); In file B: export default class UserApiControlle ...

Why does JSON remain unchanged when a value is explicitly assigned in Javascript

Why isn't my JSON structure updating when I explicitly assign a new value? items[0][i]['human_addressItem'] = address; I am trying to reverse geocode the latitude and longitude to obtain the human address, which is working fine. However, I ...

Is there a way to utilize solely Javascript in order to crop an image?

Is there a way to crop an image using plain JavaScript? I need a function that can take an image with specific width, height, offsetX, and offsetY and create a new image of the specified portion. I'm not very knowledgeable about HTML5 canvas and simi ...

Implementing sort functionality in React with filter capabilities

Is it possible to display the Sort By feature in React? Additionally, is it feasible to Filter data based on the sort category selected in the dropdown menu, which includes options such as male, female, or all? // Gather a list of names const names = data ...

Function in Typescript that accepts either a single object or an array of objects

We frequently use a simple function declaration where the function can accept either a single object or an array of objects of a certain type. The basic declaration looks like this: interface ISomeInterface { name: string; } class SomeClass { pu ...

Error encountered in jQuery's addClass and removeClass functions: Unable to read the property 'length' of an undefined value

Upon loading my page, I aim to have some of the div elements hidden initially and display only one. Here is a script that accomplishes this goal: <script> $(document).ready(function () { $(".total").click(function () { $("#pi ...

Firebase's equalTo function seems to be malfunctioning

Having encountered an issue with Firebase, I am currently attempting to fetch all of my posts in JavaScript. Specifically, I am looking for posts in the correct language that are marked as "published" and sorted by their published date. In my Firebase dat ...

Using the Selenium webdriver to reach the bottom of the page by scrolling vertically

Is there a way to determine if I have scrolled to the bottom of the page vertically? I have been using Webdriver and pressing the page down key repeatedly within a for loop, like so: for(int di=0; di<40; di++) { driver.findElement(By.tagName("body ...

The for loop does not cycle through every element

I'm working on a class project that involves creating custom HTML tags with JavaScript. I have a for loop set up to iterate over each use of the tag, but for some reason, it only seems to loop over every other tag. I'm specifically trying to crea ...

Create personalized styles for each item within a stack with specific spacing using the @mui library

Is there a way to change both the background color and spacing area when hovering over each item in my list? https://i.stack.imgur.com/87TST.png <Stack spacing={4} divider={<Divider variant={`fullWidth`} orientation={`horizontal`} flexItem/>}> ...

Validation using Joi allows for a field to be optional, but if it is included, it must be a positive integer

I am facing a challenge with a field in my JOI schema that I want to make optional, allowing for both undefined and null values. However, if a value is provided, it must be a positive integer. How can I accomplish this? So far, I have attempted the follow ...

Trigger Chrome Extension Background Page Using a Message

Currently, I am in the process of developing my initial chrome extension and focusing on establishing message passing and background.js functionality. However, it seems like my background.js file is not being triggered or receiving any messages. I am seeki ...

What could be causing the three.PointLightHelper to fail in my script?

I am encountering an issue with the line of code scene.add(new THREE.PointLightHelper(bluePoint, 3)); in my code snippet below: var bluePoint = new THREE.PointLight(0x0033ff, 100, 500); bluePoint.position.set( 500, -500, 25 ); scene.addLight(bluePoint); s ...

I am looking to pass several parameters through the post method by utilizing ajax

Can someone assist me with this code? I am trying to pass the item ID, stock quantity, and price using AJAX in a POST method. Any help would be greatly appreciated. Thank you in advance! function updateItemDetails(itemId, sellingPrice, stockQty){ v ...

What is the best method for circumventing an express middleware?

I am currently working on an express application that utilizes several express routes, such as server.get('*' , ... ) to handle common operations like authentication, validation, and more. These routes also add extra information to the respon ...