MEAN開發框架的資料很少,主要的資料還是來自於learn.mean.io網站上的介紹。於是抱著一種零基礎學習的心態,在了解的過程中,通過翻譯加上理解將MEAN框架一點點消化並且吸收,一步一步來,慢慢地記錄我學習MEAN的點點滴滴。
$ mean user2、MEAN可以列舉也可以安裝和卸載模塊$ mean user --addRole ; $ mean user --removeRole ;
$ mean list $ mean install$ mean uninstall
// Example of registering the tokens package MyPackage.register(function(app, auth, database, Tokens) { // I can make use of the tokens within my module MyPackage.someExampleFunction('some parameter'); // I can override functions MyPackage.someExampleFunction = function(param) { //my custom logic goes here }; });
// Example of adding an angular dependency of the ngDragDrop to the MyPackage.angularDependencies(['ngDragDrop']);
//Adding jquery to the mean project MyPackage.aggregateAsset('js','jquery.min.js'); //Adding another library - global by default is false MyPackage.aggregateAsset('js','jquery.min.js', {global:true}); //Adding some css to the mean project MyPackage.aggregateAsset('css','default.css');
沒有放在assets文件夾中的Javascript文件會被聚合和注入到mean項目中。如果不像這麼做,那麼應當放置在public/assets/js文件夾中。聚合操作支持控制聚合代碼所放的位置。通常需要添加一個weight和group變量來確定它是否在正確的位置。
MyPackage.aggregateAsset('js','first.js',{global:true, weight: -4, group: 'header'});
MyPackage.settings({'someSetting':'some value'}, function (err, settings) { // You will receive the settings object on success }); // Another save settings example this time with no callback // This writes over the last settings. MyPackage.settings({'anotherSettings':'some value'}); // Get settings. Retrieves latest saved settings MyPackage.settings(function (err, settings) { // You now have the settings object });當存入信息的時候,第一個參數是JSON格式信息,第二個參數是回調函數。回調函數用來判斷信息是否存入,第二個參數是可選的。當讀取信息的時候,只需要一個參數即可。這個參數就是回調函數。
// The Package is past automatically as first parameter module.exports = function(MyPackage, app, auth, database) { // example route app.get('/myPackage/example/anyone', function (req,res,next) { res.send('Anyone can access this'); }); };
$stateProvider .state('myPackage example page', { url: '/myPackage/example', templateUrl: 'myPackage/views/index.html' });
//We are adding a link to the main menu for all authenticated users MyPackage.menus.add({ title: "myPackage example page", link: "myPackage example page", roles: ["authenticated"], menu: "main" });
app.get('/myPackage/example/render', function (req,res,next) { MyPackage.render('index', {packageName:'myPackage'}, function (err, html) { //Rendering a view from the Package server/views res.send(html); }); });
MyPackage.register(function(system, app) { app.set('views', __dirname + '/server/views'); // ...
angular.module('mean.mycustompackage', ['mean.system']) .config(['$viewPathProvider', function($viewPathProvider) { $viewPathProvider.override('system/views/index.html', 'mycustompackage/views/myhomepage.html'); }]);
$ mean package
$ mean uninstall myPackage
$ mean register # register to the mean network (see below) $ cd$ mean publish