AngularJS is an MVC based framework. Google developed AngularJS. AngularJS is an open source project, which can be used freely, modified and shared by others.
Top features Of AngularJS
- Two Way Data-Binding
This means that any changes to the model update the view and any changes to the view updates the model. - Dependency Injection
AngularJS has a built-in Dependency Injection, which makes application easier to develop, maintain and debug in addition to the test. - Testing
Angular will test any of its code through both unit testing and end-to-end testing. - Model View Controller
Split your application into MVC components. Maintaining these components and connecting them together means setting up Angular.
- Visual Studio 2017 Version 15.7.3
- Microsoft .NET Framework Version 4.7
- Microsoft SQL Server 2016
- SQL Server Management Studio v17.7
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- namespace FileStructureAngular.Controllers
- {
- public class HomeController : Controller
- {
- //
- // GET: /Home/
- public ActionResult Index()
- {
- return View();
- }
- public JsonResult GetFileStructure()
- {
- List<Treeviewtbl> list = new List<Treeviewtbl>();
- using (CrystalGranite2016Entities dc = new CrystalGranite2016Entities())
- {
- list = dc.Treeviewtbls.OrderBy(a => a.FileName).ToList();
- }
- List<Treeviewtbl> treelist = new List<Treeviewtbl>();
- if (list.Count > 0)
- {
- treelist = BuildTree(list);
- }
- return new JsonResult { Data = new { treeList = treelist }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
- }
- public void GetTreeview(List<Treeviewtbl> list, Treeviewtbl current, ref List<Treeviewtbl> returnList)
- {
- var childs = list.Where(a => a.ParentID == current.ID).ToList();
- current.Childrens = new List<Treeviewtbl>();
- current.Childrens.AddRange(childs);
- foreach (var i in childs)
- {
- GetTreeview(list, i, ref returnList);
- }
- }
- public List<Treeviewtbl> BuildTree(List<Treeviewtbl> list)
- {
- List<Treeviewtbl> returnList = new List<Treeviewtbl>();
- var topLevels = list.Where(a => a.ParentID == list.OrderBy(b => b.ParentID).FirstOrDefault().ParentID);
- returnList.AddRange(topLevels);
- foreach (var i in topLevels)
- {
- GetTreeview(list, i, ref returnList);
- }
- return returnList;
- }
- }
- }
- public JsonResult GetFileStructure()
- {
- List<Treeviewtbl> list = new List<Treeviewtbl>();
- using (CrystalGranite2016Entities dc = new CrystalGranite2016Entities())
- {
- list = dc.Treeviewtbls.OrderBy(a => a.FileName).ToList();
- }
- List<Treeviewtbl> treelist = new List<Treeviewtbl>();
- if (list.Count > 0)
- {
- treelist = BuildTree(list);
- }
- return new JsonResult { Data = new { treeList = treelist }, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
- }
- public void GetTreeview(List<Treeviewtbl> list, Treeviewtbl current, ref List<Treeviewtbl> returnList)
- {
- var childs = list.Where(a => a.ParentID == current.ID).ToList();
- current.Childrens = new List<Treeviewtbl>();
- current.Childrens.AddRange(childs);
- foreach (var i in childs)
- {
- GetTreeview(list, i, ref returnList);
- }
- }
- public List<Treeviewtbl> BuildTree(List<Treeviewtbl> list)
- {
- List<Treeviewtbl> returnList = new List<Treeviewtbl>();
- var topLevels = list.Where(a => a.ParentID == list.OrderBy(b => b.ParentID).FirstOrDefault().ParentID);
- returnList.AddRange(topLevels);
- foreach (var i in topLevels)
- {
- GetTreeview(list, i, ref returnList);
- }
- return returnList;
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace FileStructureAngular
- {
- public partial class Treeviewtbl
- {
- public List<Treeviewtbl> Childrens { get; set; }
- }
- }
- angular.treeview.css
- angular.treeview.js
- image folder
- var app = angular.module('myApp', ['angularTreeview']);
- app.controller('myController', ['$scope', '$http', function ($scope, $http) {
- $http.get('/home/GetFileStructure').then(function (response) {
- $scope.List = response.data.treeList;
- })
- }])
- var app = angular.module('myApp', ['angularTreeview']);
- $http.get('/home/GetFileStructure').then(function (response) {
- $scope.List = response.data.treeList;
- })
- @{
- ViewBag.Title = "Satyaprakash - Website Modules In Treeview";
- }
- @*<h2>Website Modules In Treeview</h2>*@
- <fieldset>
- <legend style="font-family:Arial Black;color:blue">Website Modules In Treeview File Structure</legend>
- <div ng-app="myApp" ng-controller="myController">
- <span style="font-family:Arial Black;color:forestgreen">Selected Node : <span style="font-family:Arial Black;color:red">{{mytree.currentNode.FileName}}</span> </span>
- <br/>
- <br/>
- <div data-angular-treeview="true"
- data-tree-id="mytree"
- data-tree-model="List"
- data-node-id="ID"
- data-node-label="FileName"
- data-node-children="Childrens">
- </div>
- </div>
- <link href="~/Content/angular.treeview.css" rel="stylesheet" />
- @section Scripts{
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
- <script src="~/Scripts/angular.treeview.js"></script>
- <script src="~/Scripts/myApp.js"></script>
- }
- </fieldset>
- <div ng-app="myApp" ng-controller="myController">
Copy the script and css into your project and add a script and link tag to your page.
- <link href="~/Content/angular.treeview.css" rel="stylesheet" />
- @section Scripts{
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
- <script src="~/Scripts/angular.treeview.js"></script>
- <script src="~/Scripts/myApp.js"></script>
- }
Attributes of angular treeview are below.
- angular-treeview: the treeview directive.
- tree-id : each tree's unique id.
- tree-model : the tree model on $scope.
- node-id : each node's id.
- node-label : each node's label.
- node-children: each node's children.
- <div data-angular-treeview="true"
- data-tree-id="mytree"
- data-tree-model="List"
- data-node-id="ID"
- data-node-label="FileName"
- data-node-children="Childrens">
- </div>
- <span style="font-family:Arial Black;color:forestgreen">Selected Node : <span style="font-family:Arial Black;color:red">{{mytree.currentNode.FileName}}</span> </span>
- angular-treeview: the treeview directive
- tree-id : each tree's unique id.
- tree-model : the tree model on $scope.
- node-id : each node's id
- node-label : each node's label
- node-children: each node's children
- Folder or Module in the yellow icon.
- Files or Pages in the blue icon.
- Treeview using AngularJS in MVC.
- AngularTreeview directive for generating treeview from hierarchical data.
- Sample project about Modules and Pages in treeview.
- Implement Recursion method for recursively getting all children.


Sundaram SubramanianPosted Jun 19, 2018, 4:40 AM
Thanks for sharing a worth content. Keep sharing.