如何在不调用后端的 ng-admin 中添加视图?

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

我想在 ng-admin 中添加一个 static view,不需要后端调用。类似关于部分的东西。有办法吗?

没有什么特别的事情要做(这是很常见的angular方式):

只需在您的 ng-admin.js 文件中添加一条新路线(通过 $stateProvider 或 $routeProvider):

(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);
        }]);
}());

然后在你的新控制器中(位置示例:scripts/models/myCustomController.js):

'use strict';

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

app.controller('myCustomController',
        ['$scope',
            function ($scope) {
            // add your logic here
            }]);

最后,不要忘记在 index.html 中为新控制器添加 link:

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