javascript - Setting Value for Dynamic ngModel inside ngRepeat -
how set value of dynamically created ng-model inside of ng-repeat?
i'm trying set each dynamic ng-model true
or false
html file
<md-list-item ng-repeat="awayteamplayer in ulineup.awayteamplayerslineup "> <md-checkbox ng-model="ulineup.awayteamplayersplayed[awayteamplayer.player]"></md-checkbox> {{awayteamplayer.player}} </md-list-item>
controller file
(function() { angular .module('app') .controller('updatelineupcontroller', ['$routeparams', '$firebasearray', 'firebase_url', function($routeparams, $firebasearray, firebase_url) { var vm = this; var gameid = $routeparams.gameid; var lineupid = $routeparams.lineupid; var awayteamplayerslineupref = new firebase(firebase_url + 'games/' + gameid + '/lineup/' + lineupid + '/awayteamplayerslineup'); vm.awayteamplayerslineup = $firebasearray(awayteamplayerslineupref); // tried following doesn't work angular.foreach(vm.awayteamplayerslineup, function(value, key) { if(value.played === true) { // trying set ng-model value true gives me following error // typeerror: cannot set property 'mark' of undefined vm.awayteamplayersplayed[value.player] = true; } else { vm.awayteamplayersplayed[value.player] = false; } }); }]); })();
here try using init create property in memory.
<md-list-item ng-repeat="awayteamplayer in ulineup.awayteamplayerslineup "> <md-checkbox ng-init="dynamicprop = 'whatever'" ng-model="ulineup.awayteamplayersplayed[awayteamplayer.player]"></md-checkbox> {{awayteamplayer.player}} </md-list-item>
Comments
Post a Comment