我编写了一个包含三个步骤的教育页面 mainpage->allbookPage->eachbookpage->unitPage 我使用下面的 rout 在它们之间切换但是当我直接转到 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;
}
}
})