Last active
August 29, 2015 14:22
-
-
Save felippenardi/a6ec2dd4a5be9684dd53 to your computer and use it in GitHub Desktop.
AngularJS: adding and removing elements// source http://jsbin.com/buxogopavu
This file contains hidden or 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
<!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> |
This file contains hidden or 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('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