i am working on social network project which base on Itinerary Organizer and i am beginner level in Angular.. i want to get value from input and create Panels dynamically by pass value to ng-repeat attribute.. and that single Panel should be four inputs and generate set of inputs by clicking a button.. i am sharing the image of panel and inputs..Thank you
Asked
Active
Viewed 231 times
-1

Jamal Ahmad
- 571
- 2
- 9
- 25
-
Post the code you have so far. Like the code for a single panel of inputs. – Carol Skelly Feb 08 '17 at 16:20
-
What is your question? – Claies Feb 08 '17 at 16:58
3 Answers
1
Create an array for the days in your Angular scope. Then use ng-repeat
for the panels and a function to update the number of days.
myApp.controller('myController',['$scope',function($scope){
//initialize days and daysArray
$scope.days = 0;
$scope.daysArray = [$scope.days];
$scope.updateDays = function(){
$scope.daysArray = Array.apply(null, {length: $scope.days}).map(Number.call,Number);
};
}]);

Carol Skelly
- 351,302
- 90
- 710
- 624
1
Added +1 for ZimSystem reply.
I will just add one more point, move your dynamic panel code to angular directive. This will keep make any future extension easy. See this for a demo https://plnkr.co/edit/EpUTeiLgHWPr1YFAwSys?p=preview
angular.module('docsTemplateUrlDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.NoOfDays = "";
$scope.Days = [];
$scope.Add = function()
{
$scope.Days = [];
if($scope.NoOfDays != "")
{
for(i=0; i < $scope.NoOfDays;i++)
$scope.Days.push(i);
}
$scope.NoOfDays = "";
};
}])
.directive('myCustomer', function() {
return {
//your dynamic panel html
templateUrl: 'my-customer.html'
};
});

DevCod
- 280
- 2
- 11
0
Hey what you could do is this
HTML:
<input ng-model="number">
<div ng-repeat="i in getNumber(number) track by $index">
//panel html
</div>
In Controller:
$scope.number = 5;
$scope.getNumber = function(num) {
return new Array(num);
}

stackg91
- 584
- 7
- 25
-
I don't think this will work as `new Array(num)` creates an empty array with no elements. – Carol Skelly Feb 08 '17 at 16:56
-
-
Have you tried it? new Array(n) creates an EMPTY array of n length but you still need to add elements to it. [See here](http://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n) – Carol Skelly Feb 08 '17 at 17:08
-
-