Home How to push an object array into an scop array?
Reply: 0

How to push an object array into an scop array?

user1049
1#
user1049 Published in April 26, 2018, 1:43 pm

In angular js How can I push an object array into an array.

Here is my code

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body ng-app="myApp" ng-controller="myCtrl">

<h1 ng-repeat="x in records">{{x.Class}}

</h1>
<div ng-repeat="s in records.students">{{s.name}}</div>


  <input ng-model="formdata.name"  type="text" />


            <input type="button"  value="Save" ng-click="saveName(formdata)">
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [{"Class":"Class 8"}];
  $scope.saveName = function(name)
  {
    $scope.records.students.push({"name":name});
  }
});
</script>

</body>
</html>

how can I push into $scope.records.students here $scope.records is an array.

what mistake I am doing I am getting "Cannot read property 'push' of undefined"

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.505814 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO