Created
April 20, 2013 01:02
-
-
Save AndrewO/5424259 to your computer and use it in GitHub Desktop.
Angular.js: simple controls for arrays of object.
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'} | |
]; | |
}); |
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="dudes.push({})">Add</button> | |
<ul ng-repeat="dude in dudes"> | |
<li> | |
<input ng-model="dude.name"/> | |
<!-- | |
Don't forget that ng-repeat gives you boolean variables telling you | |
if you're in the $first or $last iteration. This is often useful if | |
you want to enable/disable certain actions or show/hide things for | |
only the beginning and end of the list. | |
<span ng-show="$first">The first dude.</span> | |
<span ng-show="$last">The last dude.</span> | |
--> | |
<button ng-click="dudes.splice($index,1)">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