How to call another service variable data in new service using angular js

203
December 26, 2017, at 9:12 PM
$http.get('/GetData').then(function(response) {
$scope.lastTimeStamp  = response.data.result[1].timestamp;
    var timeStamp = moment($scope.lastTimeStamp,"YYYY-MM-DD HH:mm:ss");
        if($scope.lastTimeStamp!=undefined && $scope.lastTimeStamp!=''){
            $scope.lastTimeStamp = $scope.lastTimeStamp;
        } else {
            $scope.lastTimeStamp = '';
    }
}

So, This timeStamp value I want in another service call in different page.How I can call this timeStamp and display there?

I am not much friendly to coding..Please help.

Answer 1

for data sharing across the controller in angular JS you can use localstorge, sessionstorage or $rootScope

way to share data through localstorage :

localStorage.setItem('title', $scope.title);
// Retrieve the title
$scope.title = localStorage.getItem('title'); 

way to share data through sessionStorage:

 sessionStorage.setItem(key, value);
 // to get the data 
 sessionStorage.getItem(key, value);

way to share data through rootScope:

var app = angular.module("myApp", []);
      app.run(function($rootScope) {
         $rootScope.userData = {};
         $rootScope.userData.firstName = "Ravi";
         $rootScope.userData.lastName = "Sharma";
      });

      app.controller("firstController", function($scope, $rootScope) {
           console.log($rootScope.userData.firstName)
      });
Rent Charter Buses Company
READ ALSO
How to array data extracted from this object <div class=“gwt-Label”>Some Data</div>?

How to array data extracted from this object <div class=“gwt-Label”>Some Data</div>?

How to array data extracted from this object Some Data ?

200
General SVG filter for multi-colored logos

General SVG filter for multi-colored logos

I have several PNG-logos (one solid color, solid black, solid white, black + color)I want to make one filter for all logos so that they are solid white

215
get all css value web screen which is currently open using selenium webdriver

get all css value web screen which is currently open using selenium webdriver

I am trying to get links or CSS value for current open screen not fully webpageI tried using XPath I also tried to fetch links on currently open screen but the syntax gives me all webpage links Is there any way out for this

268
Angular 2 no unique component identifier generated for select arrow div

Angular 2 no unique component identifier generated for select arrow div

I'm trying to remove the arrow from an angular material select componentTo do that I have a custom CSS file where I say display: none

332