Skip to content

Instantly share code, notes, and snippets.

@agektmr
Created July 3, 2013 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agektmr/5917056 to your computer and use it in GitHub Desktop.
Save agektmr/5917056 to your computer and use it in GitHub Desktop.
Angular controller inheritance example
<!DOCTYPE html>
<html ng-app>
<head>
<title>Angular Example</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/style.css">
<script src="scripts/angular.min.js"></script>
<script>
var ListCtrl = function($scope) {
$scope.list = [
{
name: 'agektmr',
count: 0
},
{
name: 'vvakame',
count: 0
},
{
name: 'teyosh',
count: 0
},
{
name: 'can_i_do_web',
count: 0
}
];
};
var ItemCtrl = function($scope) {
$scope.increase = function() {
$scope.item.count++;
}
}
</script>
</head>
<body>
<section ng-controller="ListCtrl">
<ul>
<li ng-repeat="item in list" ng-controller="ItemCtrl">
<p>{{item.name}}: {{item.count}} <button ng-click="increase()">+</button></p>
</li>
</ul>
</section>
<footer>
</footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment