<div>
<table ng-table="employeeSkills">
<tr ng-repeat="skill in $data">
<td data-title="'#'">{{$index + 1}}</td>
<td data-title="'Skill Type'" >
<select name="skillType_{{$index +1}}" id="skillType_{{$index +1}}" ng-model="skill.skill.type"
ng-options="type.name for type in skillTypes track by type.id"
required ng-change="skillTypeChanged(skill.skill, $index)"></select>
</td>
<td data-title="'Skill Name'" >
<select name="skillName_{{$index +1}}" id="skillName_{{$index +1}}" ng-model="skill.skill"
ng-options="skillName.skillName for skillName in (availableSkills | filter:{type: {id: skill.skill.type.id}})
track by skillName.id" ></select>
</td>
<td data-title="'Rating '" >
<span>{{skill.rating }}</span>
</td>
<td data-title="'Is Primary'" >
<input type="checkbox" ng-model="skill.isPrimary" value="{{skill.isPrimary}}" />
</td>
<td>
<button ng-click="removeSkill(skill)"> Delete </button>
</td>
</tr>
</table>
<table class="table">
<tr>
<td>
<button ng-click="addNewSkill()">Add New Skill</button>
</td>
<td>
<button ng-click="save()" >Save</button>
</td>
</tr>
</table>
</div
myApp.controller('editEmployeeSkillController', ['ngTableParams', '$scope',
function (ngTableParams, $scope) {
$scope.skillTypes = [{id: 1, name: 'Technical'},
{id: 2, name: 'Domain'},
{id: 3, name: 'Personal'}];
var skills = [{type: {id: 1, name: 'Technical'}, name: 'Java', id: 1},
{type: {id: 1, name: 'Technical'}, name: '.NET', id: 2},
{type: {id: 1, name: 'Technical'}, name: 'AngularJS', id: 3},
{type: {id: 1, name: 'Domain'}, name: 'LifeScience', id: 4},
{type: {id: 2, name: 'Domain'}, name: 'Media', id: 5},
{type: {id: 3, name: 'Personal'}, name: 'Communication', id: 6}];
$scope.availableSkills = angular.copy(skills);
$scope.originalSkills = angular.copy(skills);
var employee = {id: 1, firstName: 'Pratibha', lastName: 'Hyanki', employeeId:'xxx',
skills: [{skill: {type: {id: 1, name: 'Technical'}, name: '.Net', id: 2} isPrimary: true rating:5 id:1},
{ skill: {type: {id: 2, name: 'Domain'}, name: Media, id: 5} isPrimary:false, rating:3 id:2},
{ skill: {type: {id: 3, name: 'Personal'}, name: 'Communication', id: 6} isPrimary:true rating:1 id:3},
{ skill: {type: {id: 1, name: 'Technical'}, name: 'AngularJS', id: 3}, isPrimary: trye rating:2 id:4}
]};
$scope.employeeSkills= new ngTableParams({}, {
dataset: employee.skills,
counts: []
});
$scope.skillTypeChanged = function (skill, index) {
$scope.availableSkills = angular.copy($scope.originalSkills );
for (var i = 0; i < $scope.availableSkills.length; i++) {
if (skill.type.id == $scope.availableSkills[i].type.id) {
$scope.employeeSkills[index].skill = angular.copy($scope.availableSkills[i]);
break;
}
}
$scope.availableSkills = angular.copy($scope.originalSkills );
};
$scope.removeSkill = function (row) {
var test = row;
for (var i = 0; i < $scope.employeeSkills.length; i++) {
if (row === $scope.employeeSkills[i]) {
$scope.employeeSkills.splice(i, 1);
return;
}
}
};
$scope.addNewSkill = function () {
var row = { skill: "" id: "" isPrimary: false, rating: "" };
$scope.employeeSkills.push(row);
};
$scope.save = function () {
// code to save employee skill data
};
}]);