Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngView without routeProvider?

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?.

like image 965
akaphenom Avatar asked Nov 02 '22 15:11

akaphenom


1 Answers

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

like image 84
Mike Driver Avatar answered Nov 09 '22 13:11

Mike Driver