我想在 ng-admin 中添加静态视图,其中不需要后端调用。像约一节的东西。有没有办法做到这一点?
答案 0 :(得分:1)
没有什么特别的事情要做(这是通常的角度方式):
只需在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中添加指向新控制器的链接:
<script src="scripts/models/myCustomController.js"></script>