2014-12-11 5 views
0

아직 모호한 점이있어서 어리석은 질문을하는 경우 알려주세요! 감사.의존성 주입을 정리하는 방법은 무엇입니까?

난 내 레일 응용 프로그램에서 각도 모듈을 인스턴스 app.js 파일을 정돈하고 싶습니다. 그것은 현재이 목록은 관리하기가되도록,이

var app = angular.module('app', [ 
    'ngRoute' 
, 'ngAnimate' 
, 'ngSanitize' 
, 'ngCookies' 
, 'http-auth-interceptor' 
, 'angularFileUpload' 
, 'underscore' 
, 'angulartics' 
, 'angulartics.google.analytics' 
, 'angulartics.mixpanel' 
, 'angular-loading-bar' 
, 'mm.foundation' 

, 'directives.dateInput' 
, 'directives.elementResize' 
, 'directives.calendar.calendarResize' 
, 'directives.dayCalendar' 
, 'directives.ngEnter' 
, 'directives.datePicker' 
// ....... and so on for filters 
]); 

같이 보입니다 자동으로 다른 지시를로드 지시하고 다른 필터를로드 필터를 필요로하는 것이 가능 거대한 목록입니다?

또한 컨트롤러/지시문에 주 서비스를 삽입 할 때 주 서비스가 자동으로 다른 서비스를 주입 할 수 있습니까? 예를 들어

:

app = angular.module("app") 
app.service "ValidationService", (IdValidator) -> 
    return 

app.service "IdValidator", -> 
    @validate = (value) -> 
    #insert code 

답변

1

당신은 논리적 모듈로 분할하고 이들 모듈의 앱이 의존해야 할 수 있습니다. 예 : 지시문을 모두 하나의 모듈에 넣고이 모듈을 응용 프로그램의 종속 항목으로 추가하십시오.

당신은 여러 개의 파일로이 모듈을 분할 할 수 있습니다 (그들은 같은 "그룹"에 맞 경우)

angular.module('myDirectives', [ 
    'directives.dateInput', 
    'directives.elementResize', 
    'directives.calendar.calendarResize', 
    'directives.dayCalendar', 
    'directives.ngEnter', 
    'directives.datePicker' 
]); 

angular.module('myApp', [ 
    'myDirectives', 
    'analyticsModule', 
    'utilsServices' 
]); 
관련 문제