AngularJS_Basics7_Services

<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="myCtrl"> <p>This header will change after 2and 4 seconds:</p> <h1>{{myHeader}}</h1> <p>The url of this page is:</p> <h3>{{myUrl}}</h3> <p>Today's welcome message is:</p> <h1>{{myWelcome}}</h1> <p>The time is:</p> <h1>{{theTime}}</h1> <p>The $interval service runs a function every specified millisecond.</p> </div> <p>This example uses the built-in $location service to get the absolute url of the page.</p> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $location, $http, $timeout, $interval) { $scope.myUrl = $location.absUrl(); $http.get("welcome.htm").then(function (response) { $scope.myWelcome = response.data; }); $scope.myHeader = "Hello World!"; $timeout(function () { $scope.myHeader = "How are you today?"; }, 2000); $timeout(function () { $scope.myHeader = "How were you yesterday?"; }, 4000); $scope.theTime = new Date().toLocaleTimeString(); $interval(function () { $scope.theTime = new Date().toLocaleTimeString(); }, 1000); }); </script> </body> </html>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.