2013-11-01 3 views
3

나는 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 파일에있는 각각의 사람과 모두를 나열해야 할 것인가?

답변

2

지금 서비스가 작동 중입니다. 그건 내 잘못이야. 여기에 지금 있습니다. 나는 그것에 접근하여 그것을 사용할 수 있습니다.

define([ 
    'app' 
], 

function(app) { 
    return app.factory('serviceExample', function () { 

      return { 
       nameOfMethod: function() { 
        return "Is this working"; 
       } 
      } 
     } 
    ); 
}); 

내가 지금 궁금해하는 것이 ... 필요한 각도를 사용해야합니까?

간결한 답변없이 동일한 질문에 대해 토론하는 게시물을 많이 읽었습니다. 필자는 이전에 사용했기 때문에 require를 사용하려고 생각 했었습니다.이 응용 프로그램은 어쨌든 커다란 괴물이 될 것입니다.

의견?

+0

지연로드 또는 비동기로드 파일의 경우 requireJS를 사용해야합니다 (예 : 앱이 큰 경우). 또한 minification 또는 난독 화와 같은 파일에 대한 최적화를 수행 할 수 있습니다. – jamesjara

관련 문제