问题描述
meanjs用于前端MVC angularjs,是一个SPA的应用程序,所以当管理仪表板比前端页面不同势,究竟是落实管理仪表板的最佳方式?也许是两个接入点?
meanjs use angularjs for front end mvc , and is a SPA application , so when the admin dashboard is diffrent than the front end page , what is the best way to implement admin dashboard ? perhaps two access points ?
推荐答案
我一直在寻找一种方式也能实现这一点,我在这里发布我的搜索结果。
首先创建新的模块:
I've been looking for a way to achieve this also and I'm posting here the result of my search.First create your new module:
yo meanjs:angular-module admin
yo meanjs:angular-route adminHome
? Which module does this route belongs to? admin
? What do you want your route path to be? admin-home
? What do you want to call your view? admin-home
? What do you want to call your controller? AdminHome
create public/modules/admin/config/admin.client.routes.js
create public/modules/admin/controllers/admin-home.client.controller.js
create public/modules/admin/tests/admin-home.client.controller.test.js
create public/modules/admin/views/admin-home.client.view.html
一旦你这样做的第一步是检查,当你去:你有效地加载生成的视图。
然后你走你的生成前preSS路线和控制器:
Once you did that first step is to check that when you go on : http://localhost:3000/#!/admin-home you effectively load the generated view.Then you go generating your express route and controller:
yo meanjs:express-route admin
yo meanjs:express-controller admin
现在来这里的乐趣。这样做是为了告诉防爆preSS加载不同的组,当你打的布局视图 /管理员
Now here come the fun. The idea is to tell Express to load different set of layout views when you're hitting /admin
//Content of app/controllers/admin.server.controller.js
'use strict';
exports.index = function(req, res){
res.render('admin-index', {
user: req.user || null,
request: req
});
};
//Content of app/routes/admin.server.routes.js
'use strict';
module.exports = function(app) {
var admin = require('../../app/controllers/admin.server.controller');
app.route('/admin').get(admin.index);
};
复制/粘贴:
app/views/index.server.view.html -> app/views/admin-index.server.view.html
app/views/layout.server.view.html ->app/views/admin-layout.server.view.html
修改应用程序/视图/管理-index.server.view.html
:
{% extends 'admin-layout.server.view.html' %}
{% block content %}
<section data-ui-view></section>
{% endblock %}
修改应用程序/视图/管理-layout.server.view.html
:
[...]
{% for jsFile in jsFiles %}<script type="text/javascript" src="/{{jsFile}}"></script>{% endfor %}
[...]
的的通知/前 {{} jsFile}
的
最后的润色。由于您的浏览器现在载入/管理,而不是/你需要告诉UI路由器的路径模板是绝对的,而不是相对的。
Final touch. Because your browser is now loading /admin instead / you need to tell ui-router that the path to the templates are absolute and not relative.
//Content of public/modules/admin/config/admin.client.routes.js
'use strict';
//Setting up route
angular.module('admin').config(['$stateProvider',
function($stateProvider) {
// Admin state routing
$stateProvider.
state('admin-home', {
url: '/admin-home',
templateUrl: '/modules/admin/views/admin-home.client.view.html'
});
}
]);
的注意'/'在templateUrl内容的开头的
现在转到 HTTP测试你的管理区://本地主机:3000 /管理/#/管理到户
这篇关于meanjs如何实现管理仪表板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!