繁体   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