Skip to content

Instantly share code, notes, and snippets.

Created May 20, 2015 06:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Add text boxes dynamically using AngularJS
<div ng-app="app" ng-controller="MainCtrl" ng-init="textboxes = ['Text1','Text2','Text3']">
<div ng-repeat="box in textboxes">
<copyoftextbox ng-model="models[$index]" name={{box}} index={{$index}}></copyoftextbox>
var app = angular.module("app", []);
app.controller('MainCtrl', function($scope) {
$scope.models = ['model1','model2','model3'];
app.directive("copyoftextbox", function ($compile) {
return {
restrict: "E",
template: "<div ><input type='text' /></div>",
replace: true,
compile: function compile(tElement, tAttrs) {
return function (scope, iElement, iAttrs) {
var attributes = $(iElement).prop("attributes");
var $input = $(iElement).find("input");
$.each(attributes, function (index) {
if ( !== "class") {
$input.attr(, this.value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment