angular.module('myapp', []) .controller('MainController', ['$scope', function($scope) { $scope.users = [ {"name":"taguchi", "score":52.22}, {"name":"tanaka", "score":38.22}, {"name":"yamada", "score":11.11}, {"name":"hayashi", "score":5.25}, {"name":"tanahashi", "score":82.4}, {"name":"yasuda", "score":55.21}, {"name":"minami", "score":32.8}, {"name":"yanagi", "score":72.2} ]; }]) .controller('UserItemController', ['$scope', function($scope) { $scope.increment = function() { $scope.user.score++; }; }]);
<!DOCTYPE html> <html lang="ja" ng-app="myapp"> <head> <meta charset="UTF-8"> <title>Angularの練習</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> <script src="myscript.js"></script> </head> <body> <h1>AngularJSの練習</h1> <div ng-controller="MainController"> <ul> <li ng-repeat="user in users" ng-controller="UserItemController"> {{user.name}} {{user.score}} <button ng-click="increment()">+1</button> </li> </ul> </div> </body> </html>