angularjs - print hr depending on ng-model value -


i have input type number follows:

<input type="number" ng-model="question.numberoflines" min="1" max="5" /> 

this stored inside object on scope:

$scope.question = {        questiontext: "",        size: "",        alignment: "",        color: "",        numberoflines: "",        htmllines: "" } 

how can make when numberoflines changes of value (1,2,3,4, etc) htmllines gets same number of <hr /> value? i'm having trouble trying figure out. appreciated

you'll need create array has length equal input in order use ngrepeat directive take care of hr's:

var app = angular.module('plunker', []);  app.controller('mainctrl', function($scope) {   $scope.question = {        questiontext: "",        size: "",        alignment: "",        color: "",        numberoflines: "",        htmllines: ""   };   $scope.hrarray = [];   $scope.$watch('question.numberoflines', function(n, o) {     $scope.hrarray = [];     (var i=0; i<n; i++) {       $scope.hrarray.push('');     }   }); }); 

plunkr here


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -