我需要你们的帮助,我是 AngularJs 的新手,我有代码,代码太长,这就是我上传文档文件的原因,请检查下面的链接,使用下面的代码片段我正在验证电子邮件和密码。 customerlogin() 方法返回一些我想在下一页中显示的 JSON 数据。换句话说,我想将从 customerlogin()
返回的数据传递给 then()
,然后将其传递给/customerprofil
请帮忙,我的老板告诉我遵循此代码,但如何将数据传输到其他页面并使用 Angular js 显示,我的代码与您显示的重复代码不同
<div class="panel-body" ng-app="agfullstackApp.customerprofile">
<form action="">
<div class="form-group" ng-controller="customerprofileComponent">
<label class="col-md-2 control-label" for="inputDefault">{{full_name}}</label>
</div>
最佳答案
您可以使用 Angular 服务在页面之间共享数据。但如果刷新页面,数据就会丢失。以下是使用服务的示例。
angular.module('myServiceModule',[])
.service('myService', function() {
var savedData = {}
this.setData = function(data) {
savedData = data;
}
this.getData = function() {
return savedData;
}
});
然后从 Controller 1设置数据。
app.controller('View1Ctrl', ['myService', function(myService) {
myService.setData("some data from view 1") ;
}]);
从 Controller 2获取数据。
app.controller('View2Ctrl', ['myService', function(myService) {
console.log(myService.getData());
}]);
如果您希望数据在页面刷新后仍可用,则需要使用 localStorage。 https://github.com/grevory/angular-local-storage (最好使用 angular-local-storage 模块,因为它支持 cookie 回退,以防出现不支持的浏览器或存储容量问题)
关于javascript - 如何在AngularJS中将一页数据显示到另一页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40584620/