2013-02-26 3 views
8

requirejs 모듈을 사용하여 지시문을 요청하고 정의하는 방법을 정확히 모르겠습니다. 내 main.js 당신이 가까이있어requirejs 모듈에서 angularjs 지시문을 정의하는 방법은 무엇입니까?

require.config({ 
shim: { 
}, 

paths: { 
    angular: 'vendor/angular', 
    jquery: 'vendor/jquery.min', 
    locationBtn: 'directives/locationBtn' 
} 
}); 

require(['Zf2NVIApp', 'locationBtn'], function (app, locationBtn) { 
// use app here 
angular.bootstrap(document,['Zf2NVIApp']); 
}); 

답변

12

파일에

이이 지침의 지시를 포함하는 파일에 대한 내 코드/locationBtn.js

define(['Zf2NVIApp'], function (Zf2NVIApp) { 
    'use strict'; 

    Zf2NVIApp.directive('locationBtn', function() { 
     return { 
      template: '<div></div>', 
      restrict: 'E', 
      link: function postLink(scope, element, attrs) { 
       console.log("we are in the location btn module"); 
       element.text('this is the locationBtn directive'); 
      } 
     }; 
    }); 

}); 

이 코드입니다. 당신의 'Zf2NVIApp.js'파일 당신은 당신의 지시 AMD 모듈 정의의 값을 반환해야보다

define(['angular'], function(angular){ 
    return angular.module('Zf2NVIApp', []); 
}); 

포함되어 있음을 감안할 때 작동한다 :

define(['Zf2NVIApp'], function (Zf2NVIApp) { 
    'use strict'; 

    Zf2NVIApp.directive('locationBtn', function() { 
    return { 
     template: '<div></div>', 
     restrict: 'E', 
     link: function postLink(scope, element, attrs) { 
     console.log("we are in the location btn module"); 
     element.text('this is the locationBtn directive'); 
     } 
    }; 
    }); 

    // You need to return something from this factory function 
    return Zf2NVIApp; 

}); 
+0

그래, 그 트릭을했다. –

관련 문제