以下是我认为的相关文件:
比较组模型
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* CompareGroup Schema
*/
var CompareGroupSchema = new Schema({
created: {
type: Date,
default: Date.now
},
optionName: {
type: String,
default: '',
trim: true
},
optionAttributes: [{
attributeName: String,
optionImportance: Number,
optionScore: Number,
optionuom: String
}]
});
mongoose.model('CompareGroup', CompareGroupSchema);
比较组路线
'use strict';
var index = require('../controllers/compareGroups');
module.exports = function(app) {
app.post('/compareGroups', compareGroups.create);
};
后端控制器
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
CompareGroup = mongoose.model('CompareGroup'),
_ = require('lodash');
exports.create = function(req, res) {
var CompareGroup = new CompareGroup(req.body);
compareGroup.save(function(err) {
if (err) {
return res.send('users/signup', {
errors: err.errors,
compareGroup: compareGroup
});
} else {
res.jsonp(compareGroup);
}
});
};
还有我的前端控制器
'use strict';
angular.module('mean.compareGroups').controller('CompareGroupsController', ['$scope', '$stateParams', '$location', 'Global', 'CompareGroups', function ($scope, $stateParams, $location, Global, CompareGroups) {
$scope.global = Global;
$scope.create = function() {
var compareGroup = new CompareGroups({
//"this" is the same thing as scope
optionName: this.optionName,
optionAttributes: this.optionName.optionAttributes,
attributeName: this.optionAttributes.attributeName,
optionImportance: this.optionAttributes.optionImportance,
optionScore: this.optionAttributes.optionScore,
optionuom: this.optionAttributes.optionuom
});
compareGroup.$save(function(response) {
$location.path('compareGroups/');
});
};
}]);
当我尝试运行此代码时,我的终端显示:“.../Mean/app/routes/compareGroups app.post('/compareGroups', compareGroups.create);
^
ReferenceError:未定义 compareGroups。”
让我知道您还需要什么其他信息。谢谢!