<!DOCTYPE html>
<html ng-app="agendaEditor">
<head>
<meta charset="UTF-8">
<title>Form AgendaEditor</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="controller.js"></script>
</head>
<body ng-controller="formCtrl">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Menu</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">AgendaEditor</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-sm-6">
<table class="table">
<tr>
<td>Title</td>
<td>Name</td>
<td>Surname</td>
<td></td>
</tr>
<tr ng-repeat="item in list" ng-click="$last && addItem()">
<td><input class="form-control" type="text" ng-model="item.title"></td>
<td><input class="form-control" type="text" ng-model="item.name"></td>
<td><input class="form-control" type="text" ng-model="item.surname"></td>
<td><button ng-if="!$first" type="button" class="btn btn-danger btn-xs" ng-click="list.splice($index, 1)">-</button></td>
</tr>
</table>
<button type="button" class="btn btn-primary" ng-click="addItem()">Add</button><br />
</div>
<div class="col-sm-6">
<h3>Wynik</h3>
<div class="panel panel-default">
<div class="panel-body">
<p ng-repeat="item in myResult() track by $index">{{item}}</p>
</div>
</div>
</div>
</div>
</div><!-- /.container -->
</body>
</html>
var app = angular.module('agendaEditor', []);
app.controller('formCtrl', function($scope) {
$scope.list = [];
$scope.list.push({title: "", name: "", surname: ""});
$scope.myResult = function () {
var result = [];
for (var i = 0; i < $scope.list.length; i++) {
var concat = "„" + $scope.list[i].title + "” – " + $scope.list[i].name + " " + $scope.list[i].surname;
if($scope.list[i].title !== ""){
result.push(concat);
}
}
return result;
};
$scope.addItem = function(){
$scope.list.push({title: "", name: "", surname: ""});
};
});
body {
padding-top: 70px;
padding-bottom: 30px;
}