Is it possible to use the ng-view without writing a routeProvider
, i.e. by including the routes in the markup portion (I realize mixing logic and view is not the best design, but probably acceptable in this situation, as it is really a conditional template). My route provider has hard coded templates to angular directives:
spaceJam.config(function($routeProvider, $locationProvider) {
$routeProvider.
when('/images', {
template: '<ng-my-image-editor></ng-my-image-editor>'
}).
when('/videos', {
template: '<ng-my-video-editor></ng-my-video-editor>'
}).
when('/calendar', {
template: '<ng-my-calendar-editor></ng-my-calendar-editor>'
}).
otherwise({redirectTo: '/images'}) ;
$locationProvider.html5Mode(false);
});
instead have something like this:
<ng-view>
<ng-view-selection when="/images" default><ng-my-image-editor></ng-my-image-editor></ng-view-selection>
<ng-view-selection when="/videos"><ng-my-video-editor></ng-my-video-editor></ng-view-selection>
<ng-view-selection when="/calendar"><ng-my-calendar-editor></ng-my-calendar-editor></ng-view-selection>
<ng-view>
is there another approach to this?.
If you don't need to use a controller, ng-include is the best thing for you.
Also I would recommend taking a look at angular-ui-router's $state / $stateProvider and ui-view for what is, in my opinion, a much better approach to routing than the standard $routeProvider.
http://docs.angularjs.org/api/ng.directive:ngInclude
https://github.com/angular-ui/ui-router/wiki
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With