javascript - Angularjs: Facing issue with ng-change and ng-iterate -


problem description:

  1. whenever try select elective dropdown1, same subject code & subject credit gets populated 2nd elective well.
  2. whenever try select last value of dropdown, subjecty code & subject credit remains unchanged (i.e., previous value displayed).

i have browsed stack overflow on posts related scenario. but, couldn't find solution scenario specific. that's reason, why i'm posting question.

i'm complete newbie angularjs. appreciated. in advance!

calculateresult.html:

<tr ng-repeat="x in subjects"> <td ng-if="x.subjectcode.indexof('elective') == -1">{{ x.subjectcode }}</td> <td ng-if="x.subjectname.indexof('elective') == -1">{{ x.subjectname }}</td>             <td ng-if="x.subjectcode.indexof('elective') != -1">{{ elective.electivesubjectcode }}</td> <td ng-if="x.subjectname.indexof('elective') != -1" ng-model="elective" ng-init="increment()">     <select class="form-control" ng-init="elective = electives[index][0]" ng-model="elective" ng-options="elective.electivesubjectname elective in electives[{{index}}]" ng-change="changeselecteditem(elective.electivesubjectcode,elective.electivecredit)" required>     </select> </td> </tr> 

calculateresult.js:

var app=angular.module('myapp',[]); app.controller('myctrl',function($scope,$http,$window){   $scope.title = sessionstorage.getitem('title');   var length = sessionstorage.getitem('length');   $scope.subjects = [];   for(var i=0;i<length;i++)   { $scope.subjects.push({subjectcode:sessionstorage.getitem('subjectcode'+i),subjectname:sessionstorage.getitem('subjectname'+i),credit:sessionstorage.getitem ('credit'+i)});   }         $scope.noofelectives = sessionstorage.getitem('noofelectives');   $scope.electives = [];   $scope.electivearray = [];   $scope.elective = {};   for(var i=1;i<=$scope.noofelectives;i++)   {       $scope.electivearray = [];         for(var j=1;j<=sessionstorage.getitem('electivelength'+i);j++)       {         $scope.elective = {electivesubjectcode:sessionstorage.getitem('electivesubjectcode'+i+j),electivesubjectname:sessionstorage.getitem('electivesubjectname'+i+j),electivecredit:sessionstorage.getitem('electivecredit'+i+j)};         $scope.electivearray.push($scope.elective);       }       $scope.electives.push($scope.electivearray);   }    $scope.elective.electivesubjectcode = '--'; $scope.elective.electivecredit = '--'; $scope.index = -1;  $scope.increment=function(){   $scope.index = $scope.index + 1; }     $scope.changeselecteditem=function(electivesubjectcode,electivecredit){    $scope.elective.electivesubjectcode = electivesubjectcode;   $scope.elective.electivecredit = electivecredit;  }}); 

problem - 1: whenever try select elective 1st dropdown, subject code & subject credit gets populated 2nd elective well.

problem - 2: whenever try select last value of dropdown, subject code , subject credit remains unchanged (i.e., previous value displayed)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -