angular.module()을 여러 번 정의하는 AngularJS
전화하는 동작은 무엇입니까?angular.module('myModule')여러 번?
예를 들어 루트 및 디렉티브를 다른 .js 파일로 정의합니다.
이것은 안전합니까?
예:
//routes.js
angular.module('app',['$strap'])
.config(function($routeProvider, $locationProvider) {
...
});
//directives.js
angular.module('app')
.directive('formInput', function() {
...
또한 의존관계를 여러 번 정의하면 어떤 영향이 있습니까?이것은 첨가제입니까, 아니면 라스트 인 와인입니까?
예:
angular.module(이름[, requires], configFn);
...
필수(옵션) – {Array}=} – 지정된 경우 새 모듈을 만듭니다.지정되지 않은 경우 모듈은 추가 설정을 위해 취득됩니다. -- angular . module docs
이것은 다음과 같이 해석할 수 있습니다.의존관계를 정의할 수 있는 것은 1회뿐입니다.즉, 특정 모듈에 대해 angular.module을 처음 호출할 때 입니다.그 후 angular.module()을 여러 번 호출할 수 있지만requires옵션을 지정할 수 없습니다.
모듈을 한 번만 생성해야 합니다.문서에 따르면 이미 존재하는 이름을 가진 모듈을 생성하면 이전 모듈을 덮어씁니다.(따라서 last-in-wins)
angular.module('app', []);
원하는 경우 모듈을 원하는 횟수만큼 가져오거나 별도의 파일로 가져올 수 있습니다.일반적으로 서비스, 컨트롤러, 디렉티브 등을 선언하기 위해 모듈을 여러 번 가져옵니다.
angular.module('app').service('myService', ...);
angular.module('app').controller('myController', ...);
angular.module('app').directive('myDirective', ...);
각진 상태모듈에 대한 JS 문서는 작성 대 검색 섹션을 참조하십시오.
저는 angular는 처음이지만, 각 파일에 이름이 붙은 모듈을 하나씩 만들고, 메인 모듈에는 이러한 모듈이 필요합니다.
// in main app.js file
var app = angular.module('myapp',
['myapp.routers', 'myapp.directives', 'myapp.filters']);
// in filters.js
angular.module('myapp.filters', []).filter(....)
// in routers.js
angular.module('myapp.routers', []).router(....)
// in directives.js
angular.module('myapp.directives', []).directive(....)
언급URL : https://stackoverflow.com/questions/14371410/angularjs-defining-angular-module-multiple-times
'codememo' 카테고리의 다른 글
| Django Rest Framework 파일 업로드 (0) | 2023.03.19 |
|---|---|
| Oracle에서 변수를 선언하고 표시하는 방법 (0) | 2023.03.14 |
| material ui에서 수평 스크롤이 발생합니다. - (0) | 2023.03.14 |
| SQLite 데이터베이스에 JSON 개체를 저장하는 방법 (0) | 2023.03.14 |
| input type="number"의 경우 기본값을 0으로 설정하는 방법 (0) | 2023.03.14 |