ng-click

by rsmclaug

HTML

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<div ng-controller="MainController">
    <h3>Games</h3>
    <input type="text" ng-model="newGame"/>
    <input type="button" value="Add Game" ng-click="addGame()"/>
    <div ng-repeat="game in games">{{game}}</div>
</div>

JavaScript

var app = angular.module('myApp', []);

app.controller('MainController', function($scope) {
    $scope.games = ["Mario", "Zelda", "Metroid"];
    
    $scope.addGame = function(){
        $scope.games.push($scope.newGame);
        $scope.newGame = "";
    }
});