Skip to content

Instantly share code, notes, and snippets.

@jwood803
Last active December 22, 2015 02:48
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 jwood803/6405598 to your computer and use it in GitHub Desktop.
Save jwood803/6405598 to your computer and use it in GitHub Desktop.
Small demo for AngularJS.
var demoApp = angular.module('demoApp', []);
demoApp.controller('EmployeeController', function($scope) {
$scope.employees = [{
firstName: 'John',
lastName: 'Doe',
department: 'IT'
}];
$scope.addEmployee = function () {
$scope.employees.push({
firstName: $scope.employeeFirstName,
lastName: $scope.employeeLastName,
department: $scope.employeeDepartment
});
// Reset items for the next add
$scope.employeeFirstName = '';
$scope.employeeLastName = '';
$scope.employeeDepartment = '';
};
$scope.removeEmployee = function(index) {
$scope.employees.splice(index, 1);
};
});
<!DOCTYPE html>
<html ng-app="demoApp">
<head>
<title>AngularJS Demo - Index</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js" type="text/javascript"></script>
<script src="EmployeeController.js"></script>
</head>
<body>
<h3>Employees</h3>
<div ng-controller="EmployeeController">
<ul style="list-style-type: none">
<li ng-repeat="employee in employees">
[<a href="" ng-click="removeEmployee($index)">X</a>]
<b>Name:</b> {{ employee.firstName }} {{ employee.lastName }}
<b>Department:</b> {{ employee.department }}<br/>
</li>
</ul>
<form ng-submit="addEmployee()">
<input type="text" ng-model="employeeFirstName" placeholder="First name"/>
<input type="text" ng-model="employeeLastName" placeholder="Last name"/>
<input type="text" ng-model="employeeDepartment" placeholder="Department"/>
<input type="submit" value="Add Employee"/>
</form>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment