나는 AMD (require.js)를 사용할 보일러 각도 응용 프로그램을 준비 중입니다. 지금까지는 제대로 작동했지만 서비스에 문제가 있습니다. 서비스를 어떻게 통합합니까?Require.js를 사용하는 동안 각도로 서비스 만들기
이 Main.js이다는 :
define([
'app'
],
function(app) {
'use strict';
debugger;
return app.factory('dateGetter', [
'$scope',
function ($scope) {
$scope.getCustomName = function() {
return "THIS IS MY NAME";
}
}
]);
});
: 나는 서비스 (비참하게 여기 실패)를 개발하기 위해 노력하는 방법
define([
'app',
'../helpers/exampleFile' //example of importing custom file.js in our controller.
],
function(app, exampleFile) {
'use strict';
return app.controller('exampleTemplateController', [
'$scope', 'dateGetter',
function ($scope) {
$scope.sayHello = function(module) {
alert("Current Date: " + dateGetter.getCustomDate + " " + exampleFile(module.name));
}
}
]);
});
이것은 :
require.config({
paths: {
// These are the core components - without which our application could not run
angular: '../lib/angular/angular',
angularResource: '../lib/angular/angular-resource',
// These are components that extend our core components
jquery: '../lib/jquery/jquery-1.8.2.min',
bootstrap: '../lib/bootstrap/js/bootstrap',
underscore: '../lib/underscore/underscore',
text: '../lib/require/text'
},
shim: {
'angular' : {'exports' : 'angular'},
'angular-resource' : {deps:['angular']},
'bootstrap': {deps:['jquery']},
'underscore': {exports: '_'}
},
priority: [
"angular"
],
urlArgs: 'v=1.1'
});
require([
'angular',
'app',
'services/services',
'services/dateGetter',
'controllers/controllers',
'controllers/navbar',
'controllers/exampleTemplateController',
'filters/filters',
'directives/directives',
'routes'
], function(angular, app) {
angular.element(document).ready(function() {
angular.bootstrap(document, ['myApp']);
});
});
이것은 내가 컨트롤러를 개발하는 방법이다
나는 가깝다고 생각하지만, 뭔가 나를 벗어날 수 있습니다.
또 다른 질문은 내가 많은 컨트롤러와 서비스로 끝나면 ... 우리는 main.js 파일에있는 각각의 사람과 모두를 나열해야 할 것인가?
지연로드 또는 비동기로드 파일의 경우 requireJS를 사용해야합니다 (예 : 앱이 큰 경우). 또한 minification 또는 난독 화와 같은 파일에 대한 최적화를 수행 할 수 있습니다. – jamesjara