Created
April 20, 2013 01:04
-
-
Save AndrewO/5424267 to your computer and use it in GitHub Desktop.
Angular.js: editing arrays of objects the hard(er) way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('plunker', []); | |
app.controller('MainCtrl', function($scope) { | |
$scope.dudes=[ | |
{name:'Leonardo'}, | |
{name:'Donatello'}, | |
{name:'Raphael'}, | |
{name:'Michaelango'} | |
]; | |
// I wouldn't recommend this. See: http://plnkr.co/edit/K5vcB4v2OLGDNXzG2iNV?p=preview | |
$scope.addDude = function() { $scope.dudes.push({}); } | |
$scope.removeDude = function(dude) { | |
$scope.dudes = _($scope.dudes).without(dude); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body ng-controller="MainCtrl"> | |
<form> | |
<button ng-click="addDude()">Add</button> | |
<ul ng-repeat="dude in dudes"> | |
<li> | |
<input ng-model="dude.name"/> | |
<button ng-click="removeDude(dude)">Delete</button> | |
</li> | |
</ul> | |
</form> | |
<pre><code>{{dudes|json}}</code></pre> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://blog.econify.com/2013/04/things-i-love-about-angularjs-common.html