我定义了两个州 finance.payment 和 finance.ppm ,其中财务已经是州
这是payment.js文件
angular.module('erpSaarangFrontendApp')
.config(function ($stateProvider) {
$stateProvider
.state('finance.payment', {
url: '/payments',
templateUrl: 'views/finance/payment.html',
controller: 'FinancePaymentCtrl',
authenticate: true
});
})
.controller('FinancePaymentCtrl',['$scope', '$http','Upload','cloudinary', '$localStorage', '$state', function ($scope, $http, $upload, cloudinary, $localStorage, $state) {
var config = {
headers:{
'Authorization' : "Bearer "+ $localStorage.auth_token,
}
};
console.log($localStorage.auth_token);
}]);

payment.js的控制台输出是
y1kw3j9lhb7rj4ld8rzwkhe0a9xymwlv

这是ppm.js文件
angular.module('erpSaarangFrontendApp')
.config(function ($stateProvider) {
$stateProvider
.state('finance.ppm', {
url: '/prizemoney',
templateUrl: 'views/finance/ppm.html',
controller: 'FinancePpmCtrl',
authenticate: true
});
})
.controller('FinancePpmCtrl',['$scope','$http','Upload','cloudinary','$location','$localStorage','$state', function ($scope, $http, $upload, cloudinary, $localStorage, $state) {
var config = {
headers:{
'Authorization' : "Bearer "+ $localStorage.auth_token,
}
};
console.log($localStorage.auth_token);
}]);

ppm.js的控制台输出是
undefined

当我打印$ localStorage for payment.js时,我得到了这个 -
Object { $default: $default(), $reset: $reset(), $sync: $sync(), $apply: $apply(), $supported: $supported(), auth_token: "y1kw3j9lhb7rj4ld8rzwkhe0a9xymwlv", member: Object, _id: 8190 }

但是当我为ppm.js打印$ localStorage时,我得到了这个 -
Object { $$protocol: "http", $$host: "localhost", $$port: 9000, $$parse: LocationHashbangUrl/this.$$parse(), $$compose: LocationHashbangUrl/this.$$compose(), $$parseLinkUrl: LocationHashbangUrl/this.$$parseLinkUrl(), $$path: "/finance/prizemoney", $$search: Object, $$hash: "", $$url: "/finance/prizemoney", 4 more… }

我不明白,$ localStorage是如何变化的?以及为什么auth_token在ppm.js中未定义,而它在payment.js中有一个值
答案 0 :(得分:1)
@robin:在ppm.js文件中,您在org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON document: Can not construct instance of org.joda.time.DateTime: no String-argument constructor/factory method to deserialize from String value ('2017-05-29T20:31:57.898+02:00')
at [Source: org.apache.catalina.connector.CoyoteInputStream@36d7b26; line: 10, column: 19] (through reference chain: cc.backend.model.database.DeviceDB["device"]->cc.model.Device["lastUpdate"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.joda.time.DateTime: no String-argument constructor/factory method to deserialize from String value ('2017-05-29T20:31:57.898+02:00')
at [Source: org.apache.catalina.connector.CoyoteInputStream@36d7b26; line: 10, column: 19] (through reference chain: cc.backend.model.database.DeviceDB["device"]->cc.model.Device["lastUpdate"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:234) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readInternal(AbstractJackson2HttpMessageConverter.java:211) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:193) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:236) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.read(PersistentEntityResourceHandlerMethodArgumentResolver.java:193) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.resolveArgument(PersistentEntityResourceHandlerMethodArgumentResolver.java:141) ~[spring-data-rest-webmvc-2.6.3.RELEASE.jar:na]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ~[spring-web-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) [tomcat-embed-core-8.5.14.jar:8.5.14]
注入了$localStorage
,但在功能上它位于6 position
。
注射和传递功能的位置应该相同。
所以,实际上5th position
获取函数中的参数实际上是以$localStorage