2014-11-05 2 views
0

URL 경로 http://localhost:3000/u#/에 있으며 http://localhost:3000/u#/76457898/profile으로 이동하려면 href 링크를 클릭합니다. 서버에 요청을 보내지 않고이 작업이 필요합니다. 하지만 두 번째로 href 링크를 클릭하면됩니다.각도 UI 라우터 및 NodeJS에서 ui-sref를 사용하는 방법

처음 클릭하면 http://localhost:3000/u#/76457898으로 리디렉션됩니다. 두 번째로 페이지를 클릭 할 때 페이지가 리디렉션되지 않고 users.profile 상태 일 뿐이며 <div ui-view><div> 상태가됩니다.

http://localhost:3000/u#/http://localhost:3000/u#/76457898과 같은 페이지로 이동합니다. 각도 UI 라우터와

HTML

<a href="{{goToUIState('users.profile', user.userId)}}"> 
    <!--stuff--> 
</a> 

AngularJS와

.state('users', { 
    url: '/:userId', 
    abstract: true, 
    resolve: { 
     user: ['$cookies', '$stateParams', '$http', 'localStorageService', 
      function($cookies, $stateParams, $http, localStorageService) { 
       var uid = $cookies.uid || localStorageService.get('uid'); 
       return $http.get('/api/users/' + uid).success(function (resp) { 
        localStorageService.set('uid', uid); 
        return resp; 
       }) 
      } 
     ] 
    }, 
    views: { 
     'home': { 
      templateUrl: '/partials/user/index.html', 
      controller: ['$scope','$state', 'user', '$stateParams', function($scope, $state, user, $stateParams) { 
       $scope.user = user.data; 

       //dynamic ui-sref do not work, so creating a function to do that with $state.href() 
       $scope.goToUIState = function(state, userId) { 
        return $state.href(state, {userId: userId}); 
       } 
       $state.go('users.home'); 
      }] 
     } 
    } 
}) 

.state('users.home', { 
    url: '', 
    templateUrl: '/partials/user/users.home.html', 
    controller: [$scope', 'user', function($scope, user) { 
     $scope.user = user.data; 
    }] 

}) 

.state('users.profile', { 
    url: '/profile', 
    templateUrl: '/partials/user/users.profile.html', 
    controller: ['$scope', '$rootScope', 'user', '$http', 'fileUpload', 
     function($scope, $rootScope, user, $http, fileUpload) { 
      $scope.user = user.data; 
      //stuff 
     }] 
}) 

누군가 내가 href 링크를 클릭하는 경우에만 제가 원하는 초를 얻을 왜 뒤에 이유를 이해하는 데 도움이 수 두 번째로 어떻게 해결할 수 있습니까?

서버 측에서 NodeJS/ExpressJS를 사용하고 있습니다.

+1

나는 당신의 HTML에 혼란 스럽다. 당신은 다음과 같은 것을 사용해서는 안됩니다. [http://docs.sourceforge.net/] ? '{{ xxx }}' –

+0

@DavidSpence : '{{ xxx }}'을 사용하는 경우에도'http : // localhost : 3000/u #/76457898/profile'을 보려면 두 번 클릭해야합니다. 처음 클릭 할 때'http : // localhost : 3000/u #/76457898'에 도착하고, 두 번째로 클릭하면 마침내 원하는 http : // localhost : 3000/u #/76457898/profile'. – skip

+0

@DavidSpence : 문제는 어떻게 든 동적 바인딩 부분에있는 것처럼 보입니다. https://github.com/angular-ui/ui-router/issues/395. 동적 인 무언가를 바인딩하기 위해 내가했던 것처럼 HTML을 사용해야했습니다. – skip

답변

1

href 속성에 사용 된 기능 때문에이 문제가 발생한다고 생각합니다. 얼마 전에 비슷한 문제가 발생했습니다 (앱을 개발 중이었고 ui-router를 사용하고있었습니다). 문제는 href 내부 태그를 사용하는 데있었습니다.

나는 this question migth가 도움이된다고 생각합니다. 브라우저가 빈 href 속성을 어떻게 해석 하는지를 아는 것이 중요합니다.

다른 태그에서 함수를 사용하려고하면 ul 목록의 메뉴를 만들고 ui 요소 (ng-click 지시문)를 만듭니다. 그것은 내 경우에 도움이되었습니다.

관련 문제