Combine Two Column Using AngularJS
Submitted by razormist on Friday, June 19, 2020 - 22:04.
This code will show to do Combine Two Column using AngularJS. The code will dynamically combine the two table column into one and the content also merge. Feel free to use this code and modify as you learn from it. To learn more about this, just follow the steps below.
There you have it we successfully created a Combine Two Column using AngularJS. I hope that this very simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Getting started:
First you will need to download & install the AngularJS here's the link https://angularjs.org/. And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.Creating the Main Interface
This code contains the interface of the application. This code will render application and display the form. To do that just kindly write these block of code inside the text editor and save this as index.html.- <!DOCTYPE html>
- <html lang="en" ng-app="myModule">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body ng-controller="myController">
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- </div>
- </nav>
- <div class="col-md-6 well">
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-8">
- <table class="table table-bordered">
- <thead class="alert-info">
- <tr>
- </tr>
- </thead>
- <tbody style="background-color:#fff;">
- <tr ng-repeat="member in members">
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will combine the two column when user click the table header. To that just kindly copy and write these block of codes inside the text editor, then save it inside the js folder as script.js- var app = angular.module("myModule", [])
- .controller("myController", function($scope){
- var members = [
- {firstname: "John", lastname: "Smith", gender: "Male", address: "Hong Kong"},
- {firstname: "Steve", lastname: "Roger", gender: "Male", address: "New York"},
- {firstname: "Kate", lastname: "Sebas", gender: "Female", address: "Paris"}
- ];
- $scope.members = members;
- $scope.content = undefined;
- $scope.contentToggle = function(name){
- if ($scope.isContentToggled(name)){
- $scope.content = undefined;
- } else {
- $scope.content = name;
- }
- }
- $scope.isContentToggled = function (name){
- return $scope.content == name;
- }
- });
Add new comment
- 165 views