2016-09-19 14 views
0

要素の数を選択ボックスで指定された数値に変更したいとします。 マイコード:
ng選択に基づいて返信

のindex.php

<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> 

のindex.php

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

にDefault.js

$scope.showSelectValue = function(fieldSelect) { 
    contentFields = fieldSelect; 
    $scope.getTimes(); 
}; 

$scope.getTimes=function(n){ 
    n = contentFields; 
    return new Array(n); 
}; 

答えて

3

この作業例を試してみてください。

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>

+0

ありがとう!これは私のために働いた! – CrazzyMarc

0
あなたの機能であなたの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)); 
}; 
関連する問題