python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
add rows in angularjs

add rows in angularjs

Hello everyone, I am going to share the code sample for add the rows in display UX array collection using the angular. The code with live demo as given below.

The AngularJs code sample

   angular.module('CounterApp', [])
          .controller('CounterController', ['$scope', function ($scope) {
             
           $scope.CounterRows = [
                { name: 'Row1', web: 'www.code-sample.com' },
                { name: 'Row2', web: 'www.code-sample.net' },
                { name: 'Row3', web: 'www.code-sample.in' },
                { name: 'Row4', web: 'www.code-sample.co.in' },
                { name: 'Row5', web: 'www.code-sample.org' }];

           $scope.AddRows = function () {
                  $scope.CounterRows.push({ name: 'Row7', web: 'www.code-sample.org' });
           }
       }]);

The HTML code sample

<body ng-app="CounterApp">
    <div ng-controller="CounterController">
        <input type="button" value="Add new rows!!" ng-click="AddRows()" />
    </div>
    <div ng-repeat="row in CounterRows">
        <div>{{$index +1}}  {{row.name}}</div>
    </div>
</body>

The full live demo example code as given below

<!doctype html>
<html >
<head>
    <title>Example - www.code-sample.com</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.1/angular.min.js"></script>
    <script>
        angular.module('CounterApp', [])
          .controller('CounterController', ['$scope', function ($scope) {
              $scope.CounterRows = [
                { name: 'Row1', web: 'www.code-sample.com' },
                { name: 'Row2', web: 'www.code-sample.net' },
                { name: 'Row3', web: 'www.code-sample.in' },
                { name: 'Row4', web: 'www.code-sample.co.in' },
                { name: 'Row5', web: 'www.code-sample.org' }];

              $scope.AddRows = function () {
                  $scope.CounterRows.push({ name: 'Row7', web: 'www.code-sample.org' });
              }
          }]);
    </script>
</head>
<body ng-app="CounterApp">
    <div ng-controller="CounterController">
        <input type="button" value="Add new rows!!" ng-click="AddRows()" />
    </div>
    <div ng-repeat="row in CounterRows">
        <div>{{$index +1}}  {{row.name}}</div>
    </div>
</body>
</html>


ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions