angularjsng-admin

How to add a view in ng-admin that doesn't call backend?


I want to add a static view in ng-admin, where no backend call is required. Something like an about section. Is there a way to do that?


Solution

  • There is nothing special to do (it's quite the usual angular way):

    Just add a new route (via $stateProvider or $routeProvider) in your ng-admin.js file:

    (function () {
        "use strict";
    
        var app = angular.module('NgAdminBackend', [
            'ng-admin',
            'myNewModule', //first add a new module
        ]);
        app.config(['NgAdminConfigurationProvider', 'RestangularProvider', '$stateProvider',
            function (NgAdminConfigurationProvider, RestangularProvider, $stateProvider) {
                var nga = NgAdminConfigurationProvider;
    
                // API Endpoint
                var backend = nga.application('My Backend', false)
                        .baseApiUrl(config.BASEAPIURL);
    
                // plus if you want a menu link
                backend.menu(nga.menu()
                        .addChild(nga.menu().link('/myCustomLink').title('Hello').icon('<span class="glyphicon glyphicon-home"></span>'))
                        );
    
                // new routes here
                $stateProvider
                        .state('myCustomState', {
                            url: '/myCustomLink',
                            controller: 'myCustomController',
                            templateUrl: 'modules/myCustomTemplate.html' // example of location of your new page template
                        })
                        ;
                ...
                        nga.configure(backend);
            }]);
    }());
    

    Then in your new controller (example of location : scripts/models/myCustomController.js):

    'use strict';
    
    var app = angular.module('myNewModule', []);
    
    app.controller('myCustomController',
            ['$scope',
                function ($scope) {
                // add your logic here
                }]);
    

    And lastly, don't forget to add a link to your new controller in your index.html:

    <script src="scripts/models/myCustomController.js"></script>