2016-11-23 58 views
-1

我想重定向和一些數據傳遞給其他page.But不使用查詢字符串和URL沒有通過數據如何重定向和與POST方法

(function() { 
var app = angular.module('PlateformApp', []) 


    app.controller('PlateformController', function ($scope,$window) { 
     //This will hide the DIV by default. 
     $scope.IsVisible = false; 
     $scope.ShowHide = function (platform) { 
      //If DIV is visible it will be hidden and vice versa. 
      $scope.IsVisible = $scope.IsVisible ? true : true; 
      //alert(platform); 
      document.getElementById("platform").value = platform; 
      var myEl = angular.element(document.querySelector('#plat_val')); 
      myEl.text(platform); 
     } 

     $scope.storeAppWindow = function() 
     { 

      //store_url = $scope.storeUrl; 
      test_bc_url = "" 
      text_sh_url = "" 
      platform_val = document.getElementById("platform").value; 

      $http.get("/user/installedapp") 
       .then(function(response) { 
        $scope.myWelcome = response.data; 
      }); 

      if (platform_val == "BC") 
       $window.open(test_bc_url, "popup", "width=500,height=400,left=10,top=50"); 
      else if (platform_val == "Sh") 
       $window.open(text_sh_url, "popup", "width=500,height=400,left=10,top=50"); 

     } 
    }); 

})(); 

在這裏它會打開新的傳遞角JS數據窗口,但我想通過platform_val text_sh_url url在另一個頁面中。而且我在python中使用了flask。

+0

它只是將數據傳遞給另一個控制器在angularjs中? –

+0

我想將數據發送到其他頁面 – Piyush

+0

,這意味着您需要將數據傳遞到該特定頁面的控制器,您可以使用localstorage或通過創建服務來完成該操作。 –

回答

0

您可以通過各種方法傳遞數據,使用$stateParams,使用Storages,使用factories or services。您可以在此線程使用存儲在我的答案找到實例:sharing data using storages

(function() { 
    var app = angular.module('PlateformApp', []) 
    app.factory('newService', function() { 
    function set(data) { 
     datatosend = data; 
    } 

    function get() { 
     return datatosend; 
    } 

    return { 
     set: set, 
     get: get 
    } 
    }); 
    app.controller('PlateformController', function($scope, $window, newService) { 
    //This will hide the DIV by default. 
    $scope.IsVisible = false; 
    $scope.ShowHide = function(platform) { 
     //If DIV is visible it will be hidden and vice versa. 
     $scope.IsVisible = $scope.IsVisible ? true : true; 
     //alert(platform); 
     document.getElementById("platform").value = platform; 
     var myEl = angular.element(document.querySelector('#plat_val')); 
     myEl.text(platform); 
    } 

    $scope.storeAppWindow = function() 
    { 

     //store_url = $scope.storeUrl; 
     test_bc_url = "" 
     text_sh_url = "" 
     platform_val = document.getElementById("platform").value; 

     $http.get("/user/installedapp") 
     .then(function(response) { 
      $scope.myWelcome = response.data; 
     }); 

     if (platform_val == "BC") { 
     $window.open(test_bc_url, "popup", "width=500,height=400,left=10,top=50"); 
     } 
     else if (platform_val == "Sh") { 
     var data = { 
      'platform_val': platform_val, 
      'text_sh_url ': text_sh_url 
     }; 
     newService.set(data); 
     $window.open(text_sh_url, "popup", "width=500,height=400,left=10,top=50"); 
     } 

    } 
    }); 

})(); 

而且,在你想要得到的數據頁。只需在該頁面的控制器中注入newService並使用newService.get(data)

app.controller('pageController',function($scope,newService){ 
    var datafromanothercontroller = newService.get(data); 
    console.log(datafromanothercontroller); 
})