Well, I'm having a hard time figuring out the best way to resolve this:
I have several skills and I need to save each skill with your score and skill id for each candidate.
I have a ng-repeat that lists all the skills in the form of the candidate, I have the input of the score, but I'm having difficulty inputting the id.
I thought about creating an input, hiding it, and filling it with ids.
but the skill id values are empty using ng-model.
If I remove ng-model, the id's fill in the fields correctly.
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><formname="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>
Example of a skill model:
{_id: "56b615193afbfa041a9261b6", Name : "Javascript", Description : "Knowledge about javascript"}
Sample candidate model:
{_id: "56b615193afbfa041a9261b7", Name : "Lucas", About : "Nice guy :B", skills: [{skill : "56b615193afbfa041a9261b6", score : "90"}, {skill : ""56b615193afbfa041a9261b9", score : "70"}]};