Created
June 16, 2016 23:32
-
-
Save supercoffee/48ea24c66e121b31b7c15295cf6d539e to your computer and use it in GitHub Desktop.
Angular dynamic forms with model binding and ng-repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" ng-app="app"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body ng-controller="MyController"> | |
<form> | |
<div ng-repeat="(name, display) in form"> | |
<label for="{{ name }}">{{ display }}</label> | |
<input name="{{ name }}" type="text" ng-model="data[name]"> | |
<span>{{ data[name] }}</span> | |
</div> | |
</form> | |
</body> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> | |
<script> | |
var app = angular.module('app', []); | |
app.controller('MyController', function($scope){ | |
$scope.form = { | |
name: 'First name', | |
address: 'Address Line 1', | |
apt_num: 'Apartment/ unit number' | |
}; | |
$scope.data = {}; | |
}); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment