我正在创建一个带有角度循环的复选框:
<span ng-repeat="role in roles">
<label class="checkbox" for="{{$index}}">
<input type="checkbox" ng-model="formData.selected.ids[$index]" ng-value="role" ng-required="!formData.selected" id="{{$index}}" />
{{sport}}
</label>
</span>
架构如下所示:
var UserSchema = new Schema({
name: String,
email: { type: String, lowercase: true },
role: [{
type: String,
default: 'user'
}],
hashedPassword: String,
provider: String,
salt: String
});
在后端,我们打电话:
exports.create = function (req, res, next) {
var newUser = new User(req.body);
newUser.provider = 'local';
console.log(req.body);
newUser.role = req.body.role;
newUser.save(function(err, user) {
if (err) return validationError(res, err);
var token = jwt.sign({_id: user._id }, config.secrets.session, { expiresInMinutes: 60*5 });
res.json({ token: token });
});
};
我们如何在角色数组中保存复选框值?