Initiate a timer in AngularJS upon providing an input

Once the user makes a selection from the drop-down form, the timer should then start. However, I am unsure of how to activate it.

I have incorporated the timer module found at . While I have figured out how to stop the timer, I am seeking guidance on how to initiate it once more.

<timer interval="1000"> 
        {{hours}} hours, 
        {{minutes}} minutes, 
        {{seconds}} seconds {{millis}} 
    </timer>
    

Answer №1

Check out the documentation for more information.

When implementing in your Controller:

angular.module('MyApp', ['timer'])
    .controller('MyAppController', ['$scope', function ($scope) {
        $scope.timerRunning = true;
        $scope.startTimer = function (){
            $scope.$broadcast('timer-start');
            $scope.timerRunning = true;
        };
        $scope.stopTimer = function (){
            $scope.$broadcast('timer-stop');
            $scope.timerRunning = false;
        };
        $scope.$on('timer-stopped', function (event, data){
            console.log('Timer Stopped - data = ', data);
        });
    }]);

Incorporate this into your view:

<select ng-options="option in options" ng-change="startTimer()">
  {{option}}
</select>    
<timer/>

Remember to refer back to the documentation for further details.

I hope this guidance serves you well.

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

Guide on how to create multiple bundles using browserify and gulp

I have successfully implemented browserify to bundle up my files, but now I am faced with the challenge of generating multiple bundles. Specifically, I want to create dist/appBundle.js and dist/publicBundle.js. gulp.task("js", function(){ return brow ...

Having trouble with Material Angular NavBar not being mobile-responsive on iPhone browsers?

Exploring the world of Material Design with Angular is my latest interest. I stumbled upon this helpful guide on Angular Material from codepen and decided to give it a try. However, as I tested the code on different platforms, I noticed that while it was r ...

Error message "Truffle 'Migrations' - cb is not a valid function"

I created a straightforward smart contract using Solidity 0.6.6 and now I'm attempting to deploy it on the BSC Testnet. Here's what my truffle-config.js file looks like (privateKeys is an array with one entry ['0x + privatekey']): netw ...

A guide on transferring MySQL data from PHP to JavaScript using XMLHttpRequest and displaying the data in chronological order

After successfully retrieving the necessary MySQL data and displaying it in the notification container, I encountered an issue with manipulating the data. Instead of printing individual objects, the same object is being printed multiple times. Here is the ...

How can I make the divs resize automatically and have them equal in height when the window is resized?

I need to adjust the height of three column divs so that they are all equal. Initially, I was able to achieve this using a function found on SO (apologies for not being able to provide attribution at this time, will update if possible): function resizeIt( ...

how can I retrieve an element using a datetime in JavaScript

I have a list of appointments like the one below: 0: {start: '2022-02-23T09:30:00', end: '2022-02-23T10:00:00',…} 1: {start: '2022-02-23T10:00:00', end: '2022-02-23T10:30:00',…} 2: {start: '2022-02-2 ...

Switch off any other currently open divs

I'm currently exploring a way to automatically close other div's when I expand one. Check out my code snippet below: $( document ).ready(function() { $( ".faq-question" ).click(function() { $(this).toggleClass('open'); $(this ...

Identifying function names in Python code utilizing JavaScript regex

While using prism.js for python code highlighting, I noticed that it was not highlighting function names like deep_flatten(), flatten([1,2,3]), or flatten(list(map(lambda x: x*2,[1,2,3]))). To address this issue, I came up with the following code snippet: ...

Download multiple Highcharts graphs on a single page

When using Highchart Export, I am currently able to download multiple graphs in a single page PDF. However, I would like the first graph to be on the first page and the second graph on the second page when saving as a PDF. You can find the code in the fol ...

Error: dispatch function does not exist - TypeMismatch

Recently, I started working with react-redux and incorporated the react-thunk middleware into my project. However, I encountered an issue where I kept receiving the error "Uncaught TypeError: dispatch is not a function" whenever I attempted to execute my a ...

Is it advisable to transfer the package.json, bower.json, and gulpfile.js files to the production server?

I have implemented gulp, bower, and stylus for my angularjs project. Instead of utilizing any Continuous Integration tool, I manually fetch code from the repository with git pull whenever changes are pushed to the master branch on bitbucket. In this setup ...

Improving Vue.js CLI Performance and Enhancing Webpack Build Optimization

For a tutorial project that I've created, the code consists of no more than 100-200 lines. However, when I use webpack to build this project, the resulting bundle.js file is flagged as being larger than the recommended size. It's concerning to me ...

Filtering concatenated values from scope in ng-table

I have developed an AngularJs application using ngTable to display user data. As per the requirements, I need to filter by a concatenated string of first and last name in a single column. Despite attempting to create a custom filter following the guideline ...

JavaScript string manipulation function

Hey everyone, I need help finding a one-line solution in JavaScript to determine if a string contains a semicolon without using a loop. If anyone knows how to do this, please share your knowledge! ...

Using HTML and CSS to stack a DIV on top of another using z-index

I have 3 main layers on my website: 1) The main view with elements inside (#views in jsbin) - BOTTOM LAYER 2) An overlay (with a white background opacity of .8 #overlay in jsbin) - MIDDLE LAYER 3) A context menu (#contextmenu in jsbin) - TOP LAYER Wh ...

"Customize the appearance of your theme by adjusting the background and text colors when making a

Is there a way to dynamically change the style of a webpage based on user selection using CSS in AngularJS? I've searched online, but haven't found a solution that works for me. I have a CSS file with different styles and I want to apply these ...

Is it possible to link to a .json file stored on my server and then create a template for it?

I have set up a Webserver on kasserver.com, and I have a PHP script that retrieves data from an API every 15 minutes and saves it on my Webserver. Now, I am looking to create a template for the saved JSON data, but I am having trouble accessing it locally. ...

Changes to the ng-model are not reflecting on the user interface when using input type file

I am currently working on a straightforward example where I have a file input field and a text input field. The goal is to update the text input with the value of the selected file once a file is chosen. Here is an overview of my code: <input id="sele ...

Issues arise with the Twitter dropdown menu not displaying properly

I am currently facing an issue with my dropdown menus. I have two dropdowns on my webpage: First Dropdown: First Dropdown Code: <select name="idx" id="masthead_search"> <option value="">Library catalog</option> ...

Incorporating props into every page through getInitialProps in Next.js

I am trying to ensure that the same props are loaded on all pages I navigate to. My approach involves using _app.js as shown below: export default function MyApp({ Component, pageProps }) { return <Component {...pageProps} /> } MyApp.getInit ...