相当新的angularJS和试图将信息从一个页面传递到另一个页面。如何使用AngularJS将数据传递到不同的页面?
当前此控制器以表格格式显示客户列表,其中一列是“更多信息”。
** adminSearch.html **
<div ng-controller="adminSearch">
...
<tr ng-repeat-start="custObj in customers | filter:custSearch">
<td> {{custObj.id}} </td>
<td> {{custObj.name}} </td>
<td> <a href="#"> More Info </a></td>
</tr>
...
控制器:
** adminSearch.js **
app.controller('adminSearch', ['$scope', function($scope) {
$scope.customers = [{id:1, name:'John', email:'[email protected]', phone:'555-1276', account:123456, mylH: '1'},
{id:2, name:'Mary', email:'[email protected]', phone:'800-BIG-MARY', account:123456, mylH: '1'},
{id:3, name:'Mike', email:'[email protected]', phone:'555-4321', account:123456, mylH: '0'}];}]);
当用户从该表为客户之一点击“更多信息”我要的是,它应该去显示所有关于该信息的新页客户...
不知道的新的一页的需求,但我猜测它需要一个新的控制器:
** customerInfo.html **
<div ng-controller="customerInfo"> ... </div>
** customerInfo.js **
app.controller('customerInfo', ['$scope', function($scope) {
}]);
感谢您的帮助提前!
您可能想要编写服务并使用服务的getter setter方法跨页面共享数据。 –
您创建一个指令。在指令中你定义了你的范围,并且你可以从你的html传递数据中作为属性调用指令。 [链接] [https://docs.angularjs.org/guide/directive] –
使用$ rootScope ...这将是最简单的方式 –