我写了一个有三步主页的教育页面 - > allbookPage-> eachbookpage-> unitPage 我使用下面的溃败来切换它们但是当我直接进入每个页面并点击一个单元并转到单元页面时,单元控制器运行两次。我怎么能防止跑两次?
.state('education', {
abstract:true ,
url: "/education",
template: '<ui-view/>',
data: {
breadcrumbProxy: 'education.main'
}
})
.state('education.main', {
url: "",
templateUrl: "views/tut/education.html",
controller:"educationCtrl",
data: {
displayName: 'آموزش بورس'
},
resolve:{
titleOfPage: ['$stateParams', function($stateParams){
return $stateParams.titleOfPage = 'آموزش بورس';
}]
}
})
.state('education.books', {
abstract:true,
url: "/books",
template: '<ui-view/>',
data: {
breadcrumbProxy: 'education.books.titles'
}
})
.state('education.books.titles',{
url:"",
templateUrl: "views/tut/books.html",
controller:"booksCtrl",
data: {
displayName: 'لیست کتاب ها'
},
resolve:{
titleOfPage: ['$stateParams', function($stateParams){
return $stateParams.titleOfPage = 'لیست بخش ها';
}],
}
})
.state('education.books.content',{
abstract:true,
url: "/:bookContentId",
template: '<ui-view/>',
data: {
breadcrumbProxy: 'education.books.content.show'
}
})
.state('education.books.content.show',{
url:"",
templateUrl: "views/tut/eachBook.html",
controller:"showUnits",
data: {
displayName: 'لیست بخش ها'
},
resolve:{
titleOfPage: ['$stateParams', function($stateParams){
return $stateParams.titleOfPage = 'لیست بخش ها';
}],
bookContentId: ['$stateParams', function($stateParams,bookContentId){
return $stateParams.bookContentId;
}]
}
})
.state('education.books.content.unit',{
url:"^/education/books/:book/:unit",
templateUrl: "views/tut/units.html",
controller:"unitDetail",
data:{
displayName:'{{unitName}}',
},
resolve:{
unit: ['$stateParams', function($stateParams,unit){
return $stateParams.unit;
}],
unitName: function($stateParams, newsService) {
var st = $stateParams ;
return newsService.getUnitName($stateParams.unit).then(function(name){
st.titleOfPage = name;
return st.titleOfPage;
})
},
titleOfPage: function($stateParams, newsService) {
return $stateParams;
}
}
})
.state('education.books.content.unitrel',{
url:"/:unit",
templateUrl: "views/tut/units.html",
controller:"unitDetail",
data:{
displayName:'{{unitName}}',
},
resolve:{
unit: ['$stateParams', function($stateParams,unit){
return $stateParams.unit;
}],
unitName: function($stateParams, newsService) {
var st = $stateParams ;
return newsService.getUnitName($stateParams.unit).then(function(name){
st.titleOfPage = name;
return st.titleOfPage;
})
},
titleOfPage: function($stateParams, newsService) {
return $stateParams;
}
}
})