2016-12-16 95 views
-5

我试图在不使用服务的情况下在html页面之间传递表单数据。使用角度在html页面之间传递数据

这是我的代码链接 - >http://plnkr.co/edit/E6LM5Oq67XRcvVuMIv9i?p=preview 下面是我的contacts.html页面。

<html> 
<head> 
<title>Contacts Page</title> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular-route.js"></script> 
<script src="app.js"></script> 
</head> 
<body ng-app="myApp" > 
<table> 
<tr> 
<th>User ID</th> 
<th>First Name</th> 
<th>Last Name</th> 
<th>Phone Number</th> 
</tr> 
<tr ng-repeat="contact in contacts"> 
<td>{{contact.uid}}</td> 
<td>{{contact.fname}}</td> 
<td>{{contact.lname}}</td> 
<td>{{contact.pphone}}</td> 
</tr> 
</table> 
</body> 
</html> 

该数据没有传递给contacts.html.How to do this?

+4

请在你的问题的所有相关信息(包括代码)。看看[问]和[mcve]。 –

+0

发布代码 – Coded9

+0

两者都是不同的HTML页面。你不能传递那样的数据。 – SaiUnique

回答

-2

使用rootScope我们可以将其归档。

var app = angular.module('myApp', []); 
 
app.controller('myCtrl', function($scope, $rootScope) { 
 
    $scope.carname = "Volvo"; 
 
    $rootScope.car=$scope.carname; 
 
}); 
 
app.controller('controllerTwo', function($scope, $rootScope) { 
 
    $scope.getcarname = $rootScope.car; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 

 
<h1>{{carname}}</h1> 
 

 

 

 
<div ng-controller="controllerTwo"> 
 

 
<h1>Using rootscope: {{getcarname}}</h1> 
 

 
</div> 
 
    </div>

+2

这不是'$ rootScope'的预期目的;尽管这可能会起作用,但教这种不好的做法并不是一个好主意。 – Claies

+2

也无法解决这个问题,因为即使'$ rootScope'只能在一个角度应用程序中工作,这里的例子有两个单独的HTML页面,每个页面都有一个独特的角度应用程序。 – Claies