cypresslab/angular-ng-routing-bundle
Install Dependencies
Ensure FOSJsRoutingBundle is installed (this bundle depends on it). Add via Composer:
composer require friendsofsymfony/js-routing-bundle
Then install the target bundle:
composer require cypresslab/angular-ng-routing-bundle:dev-master
Enable the Bundle
Add to config/bundles.php:
return [
// ...
CypressLab\AngularNgRoutingBundle\CypressLabAngularNgRoutingBundle::class => ['all' => true],
];
Generate Routing Assets Run:
php bin/console assets:install public --symlink
First Use Case: Inject Routing into Angular
In your base template (e.g., base.html.twig), add these scripts after fos_js_routing_js:
<script src="{{ asset('bundles/cypressangularngrouting/ng-router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {'callback': 'cypress.NgRouter.setData'}) }}"></script>
Now NgRouting is globally available in Angular.
Expose Symfony Routes as Angular Resources
Use NgRouting.generateResourceUrl() to convert Symfony route names into Angular-compatible URLs:
// In your Angular service/controller
var resourceUrl = NgRouting.generateResourceUrl('api_user_show', { id: 123 });
$resource(resourceUrl).get().then(function(data) {
// Handle response
});
Dynamic Route Parameters Pass parameters as the second argument:
var url = NgRouting.generateResourceUrl('api_post_edit', { id: postId });
Reuse with $resource
Combine with Angular’s $resource for RESTful APIs:
var User = $resource(NgRouting.generateResourceUrl('api_user_show', { id: ':id' }));
User.get({ id: 1 }).$promise.then(...);
Global Configuration
Override default behavior in config.yml (if supported) or extend ng-router.js via custom assets.
Dependency on FOSJsRoutingBundle
FOSJsRoutingBundle is properly configured (e.g., fos_js_routing_js route exists).php bin/console debug:router
Asset Paths
ng-router.js is missing, verify:
assets:install).bundles.php.bundles/cypressangularngrouting/).Angular Scope Pollution
NgRouting is global. Avoid naming conflicts by:
app.NgRouting).Outdated Codebase
Check Router Data Log the generated data to verify routes are loaded:
console.log(cypress.NgRouter.getData());
Fallback to Manual URLs
If NgRouting fails, hardcode URLs temporarily:
$resource('/api/users/:id').get({ id: 1 });
Extend the Bundle
Override ng-router.js by copying it to web/bundles/cypressangularngrouting/ and modifying:
// Custom logic to transform routes
cypress.NgRouter.setData = function(data) {
// Preprocess data here
angular.module('yourApp').constant('NgRouting', data);
};
Symfony Cache Clear cache after route changes:
php bin/console cache:clear
How can I help you explore Laravel packages today?