在angularjs中存储常量值

在angularjs中存储常量值,angularjs,Angularjs,是否可以将所有具有指定名称的本地存储值存储在value或constant recipe中,例如: username:$localstorage.get('M_NAME') mem_id:$localstorage.get('MEMBER_ID') position:$localstorage.get('M_POSITION') 我试着这样做: .costant('client', {mem_id:$localstorage.get('MEMBER_ID')}) 但是tjis返回一个错误Ref

是否可以将所有具有指定名称的本地存储值存储在value或constant recipe中,例如:

username:$localstorage.get('M_NAME')
mem_id:$localstorage.get('MEMBER_ID')
position:$localstorage.get('M_POSITION')
我试着这样做:

.costant('client', {mem_id:$localstorage.get('MEMBER_ID')})

但是tjis返回一个错误ReferenceError:$localstorage未定义

我明白你的意思,但也许这是一个更合适的解决方案

首先,熟悉$localstorage及其文档,然后可以通过将其绑定到普通javascript$scope中的作用域变量来访问$localstorage。$storage=$localstorage将其绑定到作用域后,只需通过作用域上的新变量访问它,就可以了

    user.name = $scope.$storage.user.username
    user.id = $scope.$storage.user.id
    user.position = $scope.$storage.user.position

不,你不能这样做