【发布时间】:2016-11-30 11:09:11
【问题描述】:
我将 AngularJS 与 $stateProvider 一起使用,其中 2 个不同的状态指向相同的模板 URL。代码片段如下
$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 状态。请告诉我是什么问题?
【问题讨论】:
-
不应该是 url: url: "/training/me", for mytraining state
-
@RahulArora 谢谢.. 你拯救了我的一天。它有效..
-
我会把它写成答案。如果你能接受。
标签: angularjs angular-ui-router mean-stack