angularjs - Push To Angular JS Array -
i'm running strange issue when executing .push() method on angular js collection. in console can see object added, cannot see added list.
$scope.discountcodes.push({ discountcodeid: 0, name: $scope.discountmodel.name, code: $scope.discountmodel.code, codevalue: $scope.discountmodel.codevalue, valuetype: $scope.discountmodel.valuetype, startdate: $scope.discountmodel.startdate, enddate: $scope.discountmodel.enddate, isactive: "true" }); i have simple repeater combined template
<div ng-repeat="discount in discountcodes" ng-include="gettemplate(discount)"> </div> <script type="text/ng-template" id="display"> <div class="row"> <div class="col-md-3"> <span>name:<br />{{discount.name}}</span> </div> <div class="col-md-2"> <span>code:<br />{{discount.code}}</span> </div> <div class="col-md-2"> <span>value:<br />{{discount.codevalue}}</span> </div> <div class="col-md-2"> <span>active:<br /></span> <i class="icon-circle green-fill" ng-show="discount.isactive"> </i> <i class="icon-circle red-fill" ng-show="!discount.isactive"> </i> </div> <div class="col-md-2"><br /> <a href="#" ng-click="editdiscount(discount)" id="lnkeditrow" name="lnkeditrow" class="gray-fill"><i class="icon-edit icon-2x"></i></a> </div> </div> </script> this method: $scope.discountmodel.formsubmit = function (item, event) {
$scope.alertmessagecontainervisible = false; if ($scope.frmdiscountform.$valid) { var dataobject = { discountcodeid: 0, name: $scope.discountmodel.name, code: $scope.discountmodel.code, codevalue: $scope.discountmodel.codevalue, valuetype: $scope.discountmodel.valuetype, startdate: $scope.discountmodel.startdate, enddate: $scope.discountmodel.enddate, isactive: "true" }; action = "new"; $scope.discountcodes.push(dataobject) }); } } any ideas helpful, new angular js easy on me :)
i created simple version of below: http://plnkr.co/edit/qjdu7uiflewiojr5lyfh
it looks might updating collection outside of angular context. if so, you'll need use $scope.$apply() angular see changes.
Comments
Post a Comment