Answer the question
In order to leave comments, you need to log in
How to save in mongoose?
How to save two fields to a model
name: {
ru: {
type: String,
default: '',
required: 'Please fill field ru',
trim: true
},
en:
{
type: String,
default: '',
required: 'Please fill field en',
trim: true
}
},
? // Create new Knowledge
$scope.create = function() {
// Create new Knowledge object
var knowledge = new Knowledges ({
ru: this.name.ru,
en: this.name.en
});
// Redirect after save
knowledge.$save(function(response) {
$location.path('knowledges/' + response._id);
// Clear form fields
$scope.ru = '';
$scope.en = '';
}, function(errorResponse) {
$scope.error = errorResponse.data.message;
});
};
<div class="form-group">
<label class="control-label" for="ru">Name ru</label>
<div class="controls">
<input type="text" data-ng-model="ru" id="ru" class="form-control" placeholder="Name ru" required>
</div>
<label class="control-label" for="en">Name en</label>
<div class="controls">
<input type="text" data-ng-model="en" id="en" class="form-control" placeholder="Name en" required>
</div>
</div>
TypeError: Cannot read property 'ru' of undefined
var knowledge = new Knowledges ({
name: this.name
});
<div class="controls">
<input type="text" data-ng-model="name.ru" id="ru" class="form-control" placeholder="Name ru" required>
</div>
<label class="control-label" for="en">Name en</label>
<div class="controls">
<input type="text" data-ng-model="name.en" id="en" class="form-control" placeholder="Name en" required>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question