簡體   English   中英

在angularJS中將數據從一個html頁面傳遞到另一個html頁面

[英]Pass data from one html page to another html page in angularJS

var mainApp=angular.module('myMainApp',['ngRoute']);
mainApp.config(['$routeProvider',function($routeProvider){

    $routeProvider.when('/showData',{
    templateUrl:'C:/Users/Lala/Desktop/angularjs_lala/PassDatatoAnotherSecondPage.html',
    controller:'MainPageController'
    }).

     otherwise({
    redirectTo: 'file:///C:/Users/Lala/Desktop/angularjs_lala/PassDatatoAnotherPage.html'
  });
  }]);

        mainApp.controller('MainPageController',['$scope',function($scope){         

        console.log("In controller");

        $scope.SubmitData=function(user){

            console.log("In function");
            $scope.userData={
                  Fname:user.name,
                  Lname:user.surname,
                  Mobno:user.Mobno,
                  City:user.city
            };
            console.log($scope.userData);
            //$state.go('file:///CC:/Users/Lala/Desktop/angularjs_lala/SubmitPassedData.html');
        };
    }]);

您可以通過多種方式傳遞數據。

  1. 瀏覽器的localStorage
  2. 網址參數
  3. 服務器端會話
  4. 如今的Cookie已過時且效率低下。

您可以參考下面的鏈接了解詳細信息。

如何在angularJS中將數據從一個html頁面傳遞到另一個?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM