How to use an AngularJS custom directive with templateUrl parameter ?

Hi everyone !

Let’s consider 2 Angular modules, from 2 different OpenMRS modules:


medication.js: var medicationApp = angular.module('medication', [... ]);


dispense.js: var dispenseApp = angular.module('dispense', [... ]);

Let’s say the Medication angular module defines a custom directive named ‘order-summary’ to display any given order’s summary.


   medicationApp.directive('orderSummary', function () {
        return  {
          templateUrl: 'templates/'


  <span>Order Summary</span>

Now, I’d love to be able to use this directive in my Dispense page. dispense.gsp:


Problem is:

The directive in my page won’t work. It returns an empty directive. No error message anywhere.

But I’ve found that the problem is because the templateUrl page (templates/ from Medication module is not available when my Dispense page is loaded. Therefore the directive can’t be displayed.

Q: How to use an AngularJS custom directive with templateUrl from another module ?

The way we managed to make it work is to use template instead of templateUrl and embed the partial in the js file. The easiest way to do it is to use a tool like webpack, which embeds html partial automatically while building a bundle, see for example

OK. Thanks @raff