2016-07-26 73 views
0

我使用AngularJS與$ stateProvider與2種不同的狀態指向相同的模板。代碼段低於Angular UI路由器相同TemplateUrls問題爲不同的國家

$stateProvider 
.state('training', { 
     url: "/training", 
     templateUrl: "partials/training.html", 
     controller: function($scope, $http, $state, $uibModal){ 
      console.log("Main Training State"); 
      $http.get('/api/training').success(function (response){ 
       var data = response; 
       $scope.courses=data.courses; 
      }).error(function(err,status){ 
       console.log(err); 
      }); 
      $scope.openReadMoreModal = function (course) { 
       var modalInstance = $uibModal.open({ 
        animation: true, 
        templateUrl: 'readmoremodal.html', 
        controller: 'ModalInstanceCtrl', 
        resolve: { 
         modalObject: course 
        } 
       }); 
      }; 
     } 
    }) 
    .state('mytraining', { 
     url: "training/me", 
     templateUrl: "partials/training.html", 
     controller: function($scope, $http, $state, $uibModal){ 
      console.log("get My Events in the training html"); 
      $http.get('/api/training/myevents').success(function (response){ 
       console.log("response :"+ response); 
       $scope.courses = response.courses; 
      }).error(function(err,status){ 
       console.log(err); 
      }); 
      $scope.openReadMoreModal = function (course) { 
       var modalInstance = $uibModal.open({ 
        animation: true, 
        templateUrl: 'readmoremodal.html', 
        controller: 'ModalInstanceCtrl', 
        resolve: { 
         modalObject: course 
        } 
       }); 
      }; 
     } 
    }) 

問題是該控件不會流向mytraining狀態。請告訴我什麼是問題?

+0

應該不是網址:網址: 「/訓練/我「,爲了訓練狀態 –

+0

@RahulArora謝謝..你救了我的一天。它的工作.. –

+0

我會寫它作爲一個答案。如果你能接受它。 –

回答

1

它應該是:

url: "/training/me", 

url: "training/me", 

在mytraining狀態

0

試試這個:

.state('training', { 
    url: "/training", 
    templateUrl: "partials/training.html", 

/* ... some config ... */ 

.state('training.me', { 
     url: "/me", 
     templateUrl: "partials/training.html",