I have code that works on adding and removing entries to and from arrays in my area. At the moment, the code is not reused, but cut / pasted and configured. Also, it pretty naughtly uses area inheritance to access the array. I am trying to create a directive that will fix these two problems. The directive works fine while I add entries to the array. As soon as I delete the record, I seem to break the bi-directional binding. Any tips on how I should do this?
Fiddle is here .
It shows SkillsCtrl, which is old code, and ListEditCtrl, which is new (reproduced below from the fiddle). Adding an entry to any list will update both, but deleting an entry from one of these lists interrupts the binding.
function SkillsCtrl($scope) { $scope.addSkill = function () { $scope.profile.skills = $scope.profile.skills || []; $scope.profile.skills.push($scope.newskill); $scope.newskill = ""; }; $scope.removeSkill = function () { $scope.profile.skills = _.without($scope.profile.skills, this.skill); }; } function ListEditorCtrl($scope) { $scope.addItem = function () { $scope.list = $scope.list || []; $scope.list.push($scope.newitem); $scope.newitem = ""; }; $scope.removeItem = function () { $scope.list = _.without($scope.list, this.item); }; }
source share