angularjs - How to bring dynamicaly scope in view -


in controller have code

$scope.lists = [{ listname: 'list1' }, { listname: 'list2' }];  angular.foreach($scope.lists, function (item) {     var listname = item.listname;     $scope[listname] = [{ name: 'stefan'},{ name: 'stefan'},{ name: 'stefan'},{ name: 'stefan'}]; }); 

the input lists cames webservice, values (list1 , list2) can different each time reload app. can more 2 items in lists. how can show value $scope[listname] in ng-repat section in view?

thanks stefan

you might try this:

(function() {    angular.module("myapp", []).controller("controller", ["$scope",      function($scope) {        $scope.lists = [{          listname: "list1"        }, {          listname: "list2"        }];          angular.foreach($scope.lists, function(item) {          var listname = item.listname;          $scope[listname] = [{            name: "stefan"          }, {            name: "stefan"          }, {            name: "stefan"          }, {            name: "stefan"          }];          $scope.results = $scope[listname];        });      }    ]);  })();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div data-ng-app="myapp">    <div data-ng-controller="controller">      <ul>        <li data-ng-repeat="item in results">{{item.name}}</li>      </ul>    </div>  </div>


Comments