i new angular , having trouble updating view when variable changed. trying update view show new value of team. here controller.
app.controller('competitioncontroller', function ($scope, $log, competitionservice, teamservice) { competitionservice.getcompetitions().success(function (response) { $scope.competition = response; }, function (reason) { $scope.error = reason.data; }); $scope.team; $scope.getteams = function (competitionid) { teamservice.getteams(competitionid) .success(function (response) { $scope.team = response; $log.info($scope.team); }) .error(function (response) { console.log('get teams error: ' + response); }); } });
this view.
<tbody> <tr ng-repeat="t in team track $index"> <td>{{t}}</td> <td>{{t}}</td> </tr> </tbody>
this view loaded having no value team, value of team updated after getteams function called view. getteams function called using ng-click. thanks!!
edit full view
<div class="col-lg-12 col-sm-6 col-xs-12" ng-controller="competitioncontroller"> <div class="widget flat radius-bordered"> <div class="widget-header bg-themeprimary"> <span class="widget-caption">flat tabs in widget</span> </div> <div class="widget-body"> <div class="widget-main "> <tabset flat="true"> <tab heading="teams"> <table class="table table-hover table-striped table-bordered table-condensed"> <thead> <tr> <th>#</th> <th>name</th> </tr> </thead> <tbody> <tr ng-repeat="t in team track $index"> <td>{{t}}</td> <td>{{t}}</td> </tr> </tbody> </table> </tab> <tab heading="venues"> <p>food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid.</p> </tab> <tab heading="players"> <p>etsy mixtape wayfarers, ethical wes anderson tofu before sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade.</p> </tab> </tabset> </div> </div> </div>
solution: help, figured out problem is. had 2 views calling same controller, each view creating version of controller , variable not being updated between view. use factory change variables each controller can have access it.
there few errors code: 1) using success , error method promise response. using mix of both. should either
competitionservice.getcompetitions() .success(function (response) { $scope.competition = response; }) .error(function (reason) { $scope.error = reason.data; });
or should
competitionservice.getcompetitions().then(function (response) { $scope.competition = response; }, function (reason) { $scope.error = reason.data; });
using second method response preferred success , error deprecated in angularjs.
for viewing,
<tbody> <tr ng-repeat="t in team"> <td>{{ $index }}</td> <td>{{ t }}</td> </tr> </tbody>
this give row of team names in table. yo dont have use track $index.
Comments
Post a Comment