2014-10-29 3 views
0

현재 정상적으로 작동하는 내 정적 질문 버전이 있습니다. 문제는 루프에서 $ StateProvider를 사용하려고 할 때 JSON을 제대로 포맷 할 수없는 것입니다. 정확히 어떤 부분이 제대로 포맷되지 않았는지 확실하지 않습니다. "정의되지 않은 함수가 아닙니다"오류가 발생합니다. 하지만 아래는 내 정적 상태 정의를 뷰로 가져 와서 $ ocLazyLoad를 사용하여 해결 한 것입니다. 이 작품은 정말 내 JSON 버전 버전 루프에없는 이유는 무엇입니까?

작업 정적 버전 -이 확실히 ME는

// ABSTRACT APP LAYOUT - VIEW THAT DEFINES ENTIRE LAYOUT STRUCTURE 
$stateProvider 
    .state('app', { 
     abstract: true, 
     controller: 'LayoutCtrl', 
     templateUrl: 'app/components/core/layout/layout.html' 

    }); 

// VIEWS 
// CURRENT LAZY LOADING WAS REFERENCED FROM HERE - https://egghead.io/lessons/angularjs-lazy-loading-modules-with-ui-router-and-oclazyload 
$stateProvider 
    .state('app.dashboard', { 
     views: { 
      'feature': { 
       templateUrl: 'lazyload/components/core/features/dashboard/dashboard.html', 
       controller: "DashboardCtrl as dashboard", 
       resolve: { 
        dashboard: function ($ocLazyLoad) { 
         return $ocLazyLoad.load(
          { 
           name: "dashboard", 
           files: ["lazyload/components/core/features/dashboard/dashboard-controller.js"] 
          } 
         ) 
        } 
       } 
      } 
     } 
    }) 
    .state('app.other-feature', { 
     views: { 
      'feature': { 
       templateUrl: 'lazyload/components/core/features/other-feature/other-feature.html', 
       controller: "OtherFeatureCtrl as otherFeature", 
       resolve: { 
        otherFeature: function ($ocLazyLoad) { 
         return $ocLazyLoad.load(
          { 
           name: "otherFeature", 
           files: ["lazyload/components/core/features/other-feature/other-feature.js"] 
          } 
         ) 
        } 
       } 

      } 
     } 
    }); 

내가 분명히하고 싶은 작동, 정적 버전은 내가 작업을 얻이 수없는 것 루프 된 버전입니다, 작업을 수행합니다. 아마도 함수에 대한 어떤 종류의 배열 표기법을 적절하게 또는 무언가 수행하지 않을 것입니까? 어떤 도움이라도 대단히 감사합니다!

답변

0

사실 저는이 작업을 얻었고 응답 상태를 코드화하고 싶었습니다. 작업 상태의 독립형 배열을 볼 수있는 추상 상태와 자식 상태를 추가하는 루프를 사용하면 지연로드 컨트롤러와 지연로드 컨트롤러를 해결할 수 있습니다. $ ocLazyLoad 모듈을 통해 경로가로드되기 전에 동적으로 파일을 만듭니다.

나는 혼자만의 코드로 누군가가 저보다 어려움을 덜 수 있다고 생각했습니다. 이 서버에서로드 할 수 있도록

var states = [ 
    { "name": "app", "abstract": true, "url": "", "templateUrl": "app/components/core/layout/layout.html", "controller": "LayoutCtrl" }, 
    { 
     "name": "app.dashboard", 
     "views": { 
      "feature": { 
       "templateUrl": "lazyload/components/core/features/dashboard/dashboard.html", 
       "controller": "DashboardCtrl as dashboard", 
       "resolve": { 
        "dashboard": function ($ocLazyLoad) { 
         return $ocLazyLoad.load(
          { 
           "name": "dashboard", 
           "files": ["lazyload/components/core/features/dashboard/dashboard-controller.js"] 
          } 
         ) 
        } 
       } 
      } 
     } 
    }, 
    { 
     "name": "app.associations_hospital-surgeon", 
     "views": { 
      "feature": { 
       "templateUrl": "lazyload/components/core/features/other-feature/other-feature.html", 
       "controller": "OtherFeatureCtrl as otherFeature", 
       "resolve": { 
        "otherFeature": function ($ocLazyLoad) { 
         return $ocLazyLoad.load(
          { 
           "name": "otherFeature", 
           "files": ["lazyload/components/core/features/other-feature/other-feature.js"] 
          } 
         ) 
        } 
       } 
      } 
     } 
    } 
]; 

angular.forEach(states, function (state) { 
    console.log('state --------------------------------------------------------------------------'); 
    console.log(state); 
    $stateProvider.state(state.name, state); 
}); 

그리고 여기가 내가 JSON을 장식하지만, 기능은 JSON 파일에 유효하지 않기 때문에 사용할 때이 부착 된 함수를 정의하는 데 사용되는 사용자 정의 데이터 속성을 사용하여 날 위해 일하는 것 같았다 . 이것은 외부 또는 서버에서 파일을로드하고 필요한 경우 $ ocLazyLoad를 통해 lazyloading을 함수로 사용할 수있게했습니다.

var states = [ 
    { "name": "app", "abstract": true, "url": "", "templateUrl": "app/components/core/layout/layout.html", "controller": "LayoutCtrl" }, 
    { 
     "name": "app.dashboard", 
     "views": { 
      "feature": { 
       "templateUrl": "lazyload/components/core/features/other-feature/other-feature.html", 
       "controller": "DashboardCtrl as dashboard", 
       "resolve": {}, 
       "data": { 
        "controllerAlias": "dashboard", 
        "controllerFiles": ["lazyload/components/core/features/other-feature/other-feature.js"] 
       } 
      } 
     } 
    }, 
    { 
     "name": "app.associations_hospital-surgeon", 
     "views": { 
      "feature": { 
       "templateUrl": "lazyload/components/core/features/associations/other-feature.html", 
       "controller": "OtherFeatureCtrl as otherFeature", 
       "resolve": {}, 
       "data": { 
        "controllerAlias": "otherFeature", 
        "controllerFiles": ["lazyload/components/core/features/other-feature/other-feature.js"] 
       } 
      } 
     } 
    } 
]; 

angular.forEach(states, function (state) { 
    console.log('state --------------------------------------------------------------------------'); 
    try{ 
     console.log(state.views.feature.resolve); 
     state.views.feature.resolve[state.views.feature.data.controllerAlias] = function($ocLazyLoad){return $ocLazyLoad.load({"name": state.views.feature.data.controllerAlias,"files": state.views.feature.data.controllerFiles})}; 
    }catch(e){ 

    } 

    $stateProvider.state(state.name, state); 
});