0

I write an education page that has three step mainpage->allbookPage->eachbookpage->unitPage i use rout below for switch between them but when i directly go to eachbookpage and click on a unit and go to unitpage , unit controller run two time . how can I prevent to run two time?

.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;
                            }
                    }

        })
10
  • 2
    can you show your html?, I think you have bind ng-controller="yourController" into html. Commented Nov 1, 2015 at 7:07
  • @Shohel i didnt use ng-controller in view , all of the controllers call in js Commented Nov 1, 2015 at 7:11
  • Are you using the controller in both the parent and child states? Commented Nov 1, 2015 at 7:42
  • @AliGajani no . according to cod that i paste it in question ,parent controller is showUnits controller . Commented Nov 1, 2015 at 7:55
  • where have you called state, write that syntax. Commented Nov 1, 2015 at 7:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.