-1

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 youenter image description here

Jamal Ahmad
  • 571
  • 2
  • 9
  • 25

3 Answers3

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);
    };
}]);

http://www.codeply.com/go/HA8S1BOOA0

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);   
}

Fiddle

stackg91
  • 584
  • 7
  • 25