지시어에서 factory를 호출하지만 범위를 다시로드 한 후에도 범위가 유지되지 않습니다. 내 응용 프로그램과 함께 로그인하면 잘 작동하지만 페이지를 다시로드하면 범위가 손실됩니다. 제 지시문과 공장 코드를 공유하고 있습니다.Angular Js로 페이지를 다시로드 한 후에 지시문을 호출 할 수 없습니까?
지침
"use strict";
angular.module('app.auth').directive('loginInfo', function(User){
return {
restrict: 'A',
templateUrl: 'app/auth/directives/login.tpl.html',
link: function(scope, element){
User.initialized.then(function(){
scope.user = User
});
}
}
})
공장
'use strict';
angular.module('app').factory('User', function ($http, $q, APP_CONFIG,Rh,$rootScope,RhAuth,$location) {
var dfd = $q.defer();
var UserModel = {
initialized: dfd.promise,
username: undefined,
picture: undefined,
};
UserModel.getInfo=function(){
Rh.one('userbase/users/'+RhAuth.getUserid()).get().then(function(response)
{
UserModel.username = response.username;
UserModel.picture= response.avatar;
dfd.resolve(UserModel)
},
function (error){
dfd.resolve(error);
});
}
return UserModel;
});
login.tpl.html
<div class="login-info">
<span>
<a href="" >
<img ng-src="{{user.picture}}" alt="me" class="online">
</a>
</span>
</div>
를 다시로드하지 않고
나는 사진을 값을 유지하고 싶다.() {를 페이지 User.initialized.then (기능을 다시로드하는 것이 정의되지 않은 될 후
.
나는 하나 개의 링크 retain angular variables after page refresh을 보았다, 그러나 나는 내 문제를 해결할 수 아니다 . 페이지를 다시로드 한 후 아무것도 지속하십시오.