AngularJS Digital Clock using a Controller
Submitted by nurhodelta_17 on Thursday, January 25, 2018 - 22:38.
Add Angular JS
First, we need to add Angular JS into our html for us to use it and in this tutorial, I've used CDN so you need internet connection for it to work.
You can place the script inside your head tag or at the bottom of body tag.
Creating our Body
Next we create our body to show our clock and we also declare where we want to put our controller and ng-init function.Adding our Angular JS script
Lastly, we add our angular script where we can find our controller and myClock function.- var myApp = angular.module('myApp', []);
- myApp.controller('myCtrl', function($scope,$timeout,dateFilter) {
- $scope.myClock = function(){
- $timeout(function(){
- $scope.clock = (dateFilter(new Date(), 'hh:mm:ss a'));
- $scope.myClock();
- },1000);
- };
- });
Add new comment
- 234 views