2013-02-26 16 views
8

मुझे बिल्कुल यकीन नहीं है कि एक आवश्यकताजे मॉड्यूल का उपयोग करके निर्देश का अनुरोध कैसे करें और परिभाषित करें।हम आवश्यकताजे मॉड्यूल में एंजुलरजेस निर्देश कैसे परिभाषित करते हैं?

इस निर्देश निर्देशों युक्त फ़ाइल के लिए अपने कोड है/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'); 
      } 
     }; 
    }); 

}); 

इस कोड के लिए अपने main.js फ़ाइल

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

आप निकट पहुंच गए हैं है। यह देखते हुए कि अपने 'Zf2NVIApp.js' फ़ाइल

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

हाँ है कि चाल किया था। –

संबंधित मुद्दे