I am developing an AngularJS 1.4 Application within a Symfony2 Bundle. Symfony provides the "backend" (API) and Angular the frontend (of course).
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.
I show you my solution, which I don't like:
(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];
});
}
}());
I write my Angular Code in src/myBundle/Resources/js/
and gulp puts the final Build to src/myBundle/Resources/public/
which is then available in the Twig Template that holds the Angular app.
What I am doing right now, is basically putting the templates of my components not where they belong (that would be src/myBundle/Resources/js/components/dashboard/
for the dashboard example) but into src/myBundle/Resources/public/templates
.
I have to tell the router that the template is located elsewhere through $componentLoaderProvider.setTemplateMapping()
.
I have two Questions:
- Could I solve this template location problem in a more elegant way?
- Can I tell the router directly (in the
AppController
) where the template is?