{"id":215,"date":"2017-03-22T11:56:58","date_gmt":"2017-03-22T11:56:58","guid":{"rendered":"http:\/\/codeinsightacademy.com\/blog\/?p=215"},"modified":"2017-05-12T05:22:46","modified_gmt":"2017-05-12T05:22:46","slug":"services","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/angular-js\/services\/","title":{"rendered":"Services"},"content":{"rendered":"<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;DOCTYPE html&gt;\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;meta CHARSET=\"UTF-8\"&gt;\r\n        &lt;script src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.4.8\/angular.min.js\"&gt;&lt;\/script&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body ng-app=\"myApp\" ng-controller=\"myCtrl\"&gt;\r\n        &lt;h2&gt;Scope&lt;\/h2&gt;\r\n        &lt;fieldset&gt;\r\n            &lt;legend&gt;\r\n                Location\r\n            &lt;\/legend&gt;\r\n            &lt;div&gt;\r\n                Absolute URL {{current_url}} &lt;br\/&gt;\r\n                Protocol {{protocol}} &lt;br\/&gt;\r\n                Port {{port}} &lt;br\/&gt;\r\n                Host {{host}} &lt;br\/&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/fieldset&gt;\r\n        &lt;fieldset&gt;\r\n            &lt;legend&gt;\r\n                Timeout\r\n            &lt;\/legend&gt;\r\n            &lt;div&gt;\r\n                {{greeting}}\r\n            &lt;\/div&gt;\r\n        &lt;\/fieldset&gt;\r\n        &lt;fieldset&gt;\r\n            &lt;legend&gt;\r\n                Time Interval\r\n            &lt;\/legend&gt;\r\n            &lt;div&gt;\r\n                {{counter}}\r\n            &lt;\/div&gt;\r\n        &lt;\/fieldset&gt;\r\n        &lt;fieldset&gt;\r\n            &lt;legend&gt;\r\n                Custom Service\r\n            &lt;\/legend&gt;\r\n            &lt;div&gt;\r\n                Square of 5 is {{square}} &lt;br\/&gt;\r\n                Cube of 5 is {{cube}} &lt;br\/&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/fieldset&gt;\r\n        &lt;fieldset&gt;\r\n            &lt;legend&gt;\r\n                HTTP Service\r\n            &lt;\/legend&gt;\r\n            &lt;div&gt;\r\n                {{ajax_response}}\r\n            &lt;\/div&gt;\r\n        &lt;\/fieldset&gt;\r\n    &lt;\/body&gt;\r\n    &lt;script&gt;\r\n        var app = angular.module(\"myApp\", []);\r\n\r\n        app.service('square_cube', function () {\r\n            this.square = function (x) {\r\n                return x * x;\r\n            }\r\n\r\n            this.cube = function (x) {\r\n                return x * x * x;\r\n            }\r\n        });\r\n\r\n        app.controller(\"myCtrl\", function ($scope, $location, $timeout, $interval, square_cube, $http) {\r\n\r\n            $scope.current_url = $location.absUrl();\r\n            $scope.protocol = $location.protocol();\r\n            $scope.port = $location.port();\r\n            $scope.host = $location.host();\r\n\r\n            $timeout(function () {\r\n                $scope.greeting = \"Hello India\"\r\n            }, 5000);\r\n\r\n            $scope.counter = 0;\r\n\r\n            $interval(function () {\r\n                $scope.counter = $scope.counter + 1;\r\n            }, 1000);\r\n\r\n            $scope.square = square_cube.square(5);\r\n            $scope.cube = square_cube.cube(5);\r\n\r\n            $http.get('ajax_response.html').then(function (response) {\r\n                $scope.ajax_response = response.data[1].name;\r\n            });\r\n\r\n        });\r\n    &lt;\/script&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &lt;DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta CHARSET=&#8221;UTF-8&#8243;&gt; &lt;script src=&#8221;http:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.4.8\/angular.min.js&#8221;&gt;&lt;\/script&gt; &lt;\/head&gt; &lt;body ng-app=&#8221;myApp&#8221; ng-controller=&#8221;myCtrl&#8221;&gt; &lt;h2&gt;Scope&lt;\/h2&gt; &lt;fieldset&gt; &lt;legend&gt; Location &lt;\/legend&gt; &lt;div&gt; Absolute URL {{current_url}} &lt;br\/&gt; Protocol {{protocol}} &lt;br\/&gt; Port {{port}} &lt;br\/&gt; Host {{host}} &lt;br\/&gt; &lt;\/div&gt; &lt;\/fieldset&gt; &lt;fieldset&gt; &lt;legend&gt; Timeout &lt;\/legend&gt; &lt;div&gt; {{greeting}} &lt;\/div&gt; &lt;\/fieldset&gt; &lt;fieldset&gt; &lt;legend&gt; Time Interval &lt;\/legend&gt; &lt;div&gt; {{counter}} &lt;\/div&gt; &lt;\/fieldset&gt; &lt;fieldset&gt; &lt;legend&gt; Custom Service [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"quote","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/215"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":11,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":258,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions\/258"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}