3
Well, I’m having a little trouble figuring out the best way to solve this:
I have several Skills and need to save each Skill with its score and id(from Skill) for each candidate.
have an ng-repeat listing all the Skills in the candidate form, have the score input, only I’m having difficulties in id input.
thought to create an input, hide it, and fill it with the ids.
but Skill id values are empty using ng-model.
If I remove ng-model, id’s correctly fill in the fields.
angular.module('Project').controller('CandidateController', function ($scope, $http){
$scope.skills = [];
$scope.candidate = {};
$scope.candidate.skills = [];
$http.get('/skill')
.success(function (data){
$scope.skills = data;
})
.error(function(error){
console.log(error)
});
$scope.submit = function(){
console.log($scope.candidate);
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<form name="form" class="row" ng-submit="submit()">
<div class="col-md-6">
<label>Candidate Name</labe>
<input name="Name" class="form-control" ng-model="candidate.name"></input>
<label>About Candidate</label>
<textarea rows="5" cols="20" name="About" ng-model="candidate.about" class="form-control"></textarea>
<hr>
</div>
<div class="col-md-2">
<div ng-repeat="skill in skills">
<label>{{skill.Name}}</label>
<input ng-model="candidate.skills[$index].score" class="form-control"></input>
<input ng-model="candidate.skills[$index].skill" class="form-control" ng-value="skill._id"></input>
</div>
</div>
<button type="submit" class="btn btn-primary">
Save
</button>
<a href="/candidates" class="btn btn-primary">Back</a>
</form>
Model example of a Skill :
{_id: "56b615193afbfa041a9261b6", Name : "Javascript", Description : "Knowledge about javascript"}
Model example of a candidate :
{_id: "56b615193afbfa041a9261b7", Name : "Lucas", About : "Nice guy :B", skills: [{skill : "56b615193afbfa041a9261b6", score : "90"}, {skill : ""56b615193afbfa041a9261b9", score : "70"}]};
Add an example from the Skills collection, Lucas?
– OnoSendai
{_id : '56b615193afbfa041a9261b6', Name : 'Javascript', Description : 'Knowledge about javascript'}, this?
– Lucas Fantacucci
Exact. Add a slightly larger set to the question body - this will help contributors view a solution to their problem.
– OnoSendai