Skip to content

Instantly share code, notes, and snippets.

@felippenardi
Last active August 29, 2015 14:22
Show Gist options
  • Save felippenardi/a6ec2dd4a5be9684dd53 to your computer and use it in GitHub Desktop.
Save felippenardi/a6ec2dd4a5be9684dd53 to your computer and use it in GitHub Desktop.
AngularJS: adding and removing elements// source http://jsbin.com/buxogopavu
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<title>AngularJS: adding and remove elements</title>
</head>
<body>
<div ng-controller="DemoCtrl as Demo">
<a href="" ng-click="Demo.data[Demo.data.length] = {}">Add element</a>
<ul>
<li ng-repeat="data in Demo.data">
<input type=text ng-model="data.text">
<a href="" ng-click="Demo.data.splice($index,1)">×</a>
</li>
</ul>
{{Demo.data}}
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.9/angular.js"></script>
<script id="jsbin-javascript">
var app = angular.module('myApp', []);
app.controller('DemoCtrl', function() {
this.data = [
{ text: 'Ruby' },
{ text: 'Node' },
{ text: 'Go' },
{ text: 'Python' }
];
});
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<title>AngularJS: adding and remove elements</title>
</head>
<body>
<div ng-controller="DemoCtrl as Demo">
<a href="" ng-click="Demo.data[Demo.data.length] = {}">Add element</a>
<ul>
<li ng-repeat="data in Demo.data">
<input type=text ng-model="data.text">
<a href="" ng-click="Demo.data.splice($index,1)">×</a>
</li>
</ul>
{{Demo.data}}
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.9/angular.js"><\/script>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">var app = angular.module('myApp', []);
app.controller('DemoCtrl', function() {
this.data = [
{ text: 'Ruby' },
{ text: 'Node' },
{ text: 'Go' },
{ text: 'Python' }
];
});</script></body>
</html>
var app = angular.module('myApp', []);
app.controller('DemoCtrl', function() {
this.data = [
{ text: 'Ruby' },
{ text: 'Node' },
{ text: 'Go' },
{ text: 'Python' }
];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment