title: Best Practice with AngularJS template locations in Symfony 2 with the new Angular Router?
body: <p>I am developing an AngularJS 1.4 Application within a Symfony2 Bundle. Symfony provides the &quot;backend&quot; (API) and Angular the frontend (of course).</p>
  <p>I am using the new router and stick to the components driven folder approach suggested by several guides and best practice examples. But since I build my JavaScript with gulp and only include the complete Build-Files there are issues with Angular controllers not finding their templates.</p>
  <p>I show you my solution, which I don't like:</p>
  <pre><code>(function () {
  'use strict';
  angular
      .module('myModule', ['ngNewRouter', 'myModule.dashboard'])
      .config(TemplateMapping)
      .controller('AppController', AppController);
  
  /* @ngInject */
  function AppController ($router) {
      $router.config([
          { path: '/', redirectTo: '/dashboard' },
          { path: '/dashboard', component: 'dashboard' }
      ]);
  }
  
  /* @ngInject */
  function TemplateMapping($componentLoaderProvider) {
      $componentLoaderProvider.setTemplateMapping(function (name) {
          return {
              'dashboard': '/bundles/mybundle/templates/dashboard/dashboard.html'
          }[name];
      });
  }
  }());
  </code></pre>
  <p>I write my Angular Code in <code>src/myBundle/Resources/js/</code> and gulp puts the final Build to <code>src/myBundle/Resources/public/</code> which is then available in the Twig Template that holds the Angular app.</p>
  <p>What I am doing right now, is basically putting the templates of my components not where they belong (that would be <code>src/myBundle/Resources/js/components/dashboard/</code> for the dashboard example) but into <code>src/myBundle/Resources/public/templates</code>.</p>
  <p>I have to tell the router that the template is located elsewhere through <code>$componentLoaderProvider.setTemplateMapping()</code>.</p>
  <p>I have two Questions:</p>
  <ol>
  <li>Could I solve this template location problem in a more elegant way?</li>
  <li>Can I tell the router directly (in the <code>AppController</code>) where the template is?</li>
  </ol>