Igor G. Igor G. - 1 year ago 77
AngularJS Question

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?

Answer Source

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', [
        '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)

            // plus if you want a menu link
                    .addChild(nga.menu().link('/myCustomLink').title('Hello').icon('<span class="glyphicon glyphicon-home"></span>'))

            // new routes here
                    .state('myCustomState', {
                        url: '/myCustomLink',
                        controller: 'myCustomController',
                        templateUrl: 'modules/myCustomTemplate.html' // example of location of your new page template

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

'use strict';

var app = angular.module('myNewModule', []);

            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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download