代码之家  ›  专栏  ›  技术社区  ›  CrazzyMarc Nilesh Mahajan

ngRepeat基于选择

  •  0
  • CrazzyMarc Nilesh Mahajan  · 技术社区  · 8 年前

    我想将元素的数目更改为选择框给定的数目。

    <select class="form-control-static" ng-model="fieldSelect" ng-change="showSelectValue(fieldSelect)">
        <option ng-repeat="i in getNumber(number) track by $index" value="{{$index+1}}">{{$index+1}}</option>
    </select>
    

    索引.php

    <div ng-repeat="t in getTimes(1) track by $index")>
        Hello!
    </div>
    

    默认.js

    $scope.showSelectValue = function(fieldSelect) {
        contentFields = fieldSelect;
        $scope.getTimes();
    };
    
    $scope.getTimes=function(n){
        n = contentFields;
        return new Array(n);
    };
    
    2 回复  |  直到 8 年前
        1
  •  3
  •   Mohit Tanwani    8 年前

    试试这个工作示例。

    var myApp = angular.module('myApp',[]);
    
    myApp.controller('GreetingController', ['$scope', function($scope) {
      $scope.getTimes=function(n){
       // Parse the value to int
       return new Array(parseInt(n));
    };
    }]);
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <div ng-app="myApp" ng-controller="GreetingController">
    <select class="form-control-static" ng-model="fieldSelect" ng-init="fieldSelect=1">
        <option ng-repeat="i in [1,2,3,4,5] track by $index" value="{{$index+1}}">{{$index+1}}</option>
    </select>
      
    <div ng-repeat="t in getTimes(fieldSelect) track by $index")>
        Hello! {{$index}}
    </div>
    </div>
        2
  •  0
  •   jaguwalapratik    8 年前

    在html中

    <div ng-repeat="t in getTimes({{fieldSelect}}) track by $index")>
       Hello!
    </div>
    

    在您的功能中

    $scope.getTimes=function(n){
       // Parse the value to int
       return new Array(parseInt(n));
    };