{"id":1518,"date":"2016-05-15T13:22:33","date_gmt":"2016-05-15T13:22:33","guid":{"rendered":"http:\/\/box.jharaphula.com\/?p=1518"},"modified":"2024-01-27T04:07:53","modified_gmt":"2024-01-27T09:37:53","slug":"example-angular-treeview-json","status":"publish","type":"post","link":"https:\/\/jharaphula.com\/example-angular-treeview-json\/","title":{"rendered":"Example of Angular Treeview using Data from a JSON File"},"content":{"rendered":"<p>JSON is one of the most popular lightweight data inter-exchange platform. It is platform independent and can easily editable without using any specific tool. Simply using Notepad you can read or write to a JSON file. Looking into this nearly all advanced third-party components supports JSON formatted data. In this regard here I am with a demo app to show you how to create Angular Treeview using data from a JSON file. This example is very helpful for the beginners of AngularJS.<\/p>\n<p>Look at the example below here I have a <a href=\"https:\/\/jharaphula.com\/learn-json-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noopener noreferrer\">JSON<\/a> file &#8220;treeview.json&#8221; which holds the required data for my Angular Treeview. As you know to design a Treeview we required formatted data. That&#8217;s why here my JSON file has two kind of data nodes &amp; sub-nodes. To display JSON data in a Treeview here I used $http module get() method to fetch data. After successful response from get() method assigning the response data to $scope object &#8220;items&#8221; array. showSubnodes() function is to display sub-nodes under respective parent node. In view to display items I am using UL LI elements. Using ng-repeat here I am looping the data &amp; binding each record to li elements. 2 UL elements I used here. One for parent nodes &amp; other one for Sub-nodes.<\/p>\n<h2>Example of Angular Treeview using Data<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3511\" title=\"Angular Treeview\" src=\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/angularjs-json-treeview.png\" alt=\"Angular Treeview\" width=\"750\" height=\"270\" srcset=\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/angularjs-json-treeview.png 750w, https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/angularjs-json-treeview-300x108.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<h3>index.htm<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">&lt;!DOCTYPE html&gt;\r\n&lt;html ng-app=&quot;myTreeview&quot;&gt;\r\n&lt;head&gt;\r\n&lt;title&gt;Angular Treeview using data from a JSON File&lt;\/title&gt;\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;https:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.3.0-rc.0\/angular.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script type=&quot;text\/javascript&quot;&gt;\r\nvar myTreeview = angular.module('myTreeview', []);\r\nmyTreeview.controller('treeviewCtrl', function($scope, $http) {\r\n$http.get(&quot;treeview.json&quot;).success(function (response) {\r\n\/*After Successful Response binding the JSON data to items array in Scope object*\/\r\n$scope.items = response.treedata;\r\n});\r\n$scope.showSubnodes = function(item){\r\nitem.active = !item.active;\r\n};\r\n});\r\n&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body ng-controller=&quot;treeviewCtrl&quot;&gt;\r\n&lt;ul&gt;\r\n&lt;li ng-repeat=&quot;item in items&quot; ng-click=&quot;showSubnodes(item)&quot;&gt;\r\n&lt;span&gt;{{item.node}}&lt;\/span&gt;\r\n&lt;ul&gt;\r\n&lt;li ng-repeat=&quot;subItem in item.subnodes&quot; ng-show=&quot;item.active&quot;&gt;\r\n&lt;span&gt;{{subItem.subnode}}&lt;\/span&gt;\r\n&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;\/li&gt;\r\n&lt;\/ul&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<h2>JSON File for Angular Treeview<\/h2>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">{&quot;treedata&quot;:\r\n[\r\n{\r\n&quot;node&quot;: &quot;Company&quot;,\r\n&quot;subnodes&quot;: [\r\n{&quot;subnode&quot;: &quot;About Us&quot;},\r\n{&quot;subnode&quot;: &quot;Press Release&quot;},\r\n{&quot;subnode&quot;: &quot;Contact Us&quot;},\r\n{&quot;subnode&quot;: &quot;Our Blog&quot;},\r\n{&quot;subnode&quot;: &quot;Privacy&quot;}\r\n]\r\n},\r\n{\r\n&quot;node&quot;: &quot;Services&quot;,\r\n&quot;subnodes&quot;: [\r\n{&quot;subnode&quot;: &quot;VOIP&quot;},\r\n{&quot;subnode&quot;: &quot;Web Designing&quot;},\r\n{&quot;subnode&quot;: &quot;Photo Editing&quot;},\r\n{&quot;subnode&quot;: &quot;Audio &amp; Video Processing&quot;},\r\n{&quot;subnode&quot;: &quot;Logo Designing&quot;}\r\n]\r\n},\r\n{\r\n&quot;node&quot;: &quot;Products&quot;,\r\n&quot;subnodes&quot;: [\r\n{&quot;subnode&quot;: &quot;CMS&quot;},\r\n{&quot;subnode&quot;: &quot;Blog Posting&quot;},\r\n{&quot;subnode&quot;: &quot;Forum Marketing&quot;},\r\n{&quot;subnode&quot;: &quot;Template Creation&quot;}\r\n]\r\n}\r\n]\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JSON is one of the most popular lightweight data inter-exchange platform. It is platform independent and can easily editable without using any specific tool. Simply&#8230;<\/p>\n","protected":false},"author":3,"featured_media":1927,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[38471,39537,39426,37157,39538],"class_list":["post-1518","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn-angularjs-with-examples","tag-angularjs-with-examples","tag-example-of-angular-treeview","tag-json-tutorial-for-beginners","tag-treeview-example","tag-treeview-using-data-from-a-json-file"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Example of Angular Treeview using data from a JSON File<\/title>\n<meta name=\"description\" content=\"JSON is a lightweight data inter-exchange platform. Would you like to create a Angular Treeview using data from a JSON file? If so, Look at this example.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Example of Angular Treeview using data from a JSON File\" \/>\n<meta property=\"og:description\" content=\"JSON is a lightweight data inter-exchange platform. Would you like to create a Angular Treeview using data from a JSON file? If so, Look at this example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\" \/>\n<meta property=\"og:site_name\" content=\"OneStop Shop\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/tajinweb\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-15T13:22:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-27T09:37:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"436\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nibedita Panda\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nibedita Panda\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\"},\"author\":{\"name\":\"Nibedita Panda\",\"@id\":\"https:\/\/jharaphula.com\/#\/schema\/person\/129213d91cdcccd8f9396797c56e7dc3\"},\"headline\":\"Example of Angular Treeview using Data from a JSON File\",\"datePublished\":\"2016-05-15T13:22:33+00:00\",\"dateModified\":\"2024-01-27T09:37:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\"},\"wordCount\":555,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/jharaphula.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png\",\"keywords\":[\"AngularJS with Examples\",\"Example of Angular Treeview\",\"JSON Tutorial for beginners\",\"Treeview Example\",\"Treeview using Data from a JSON File\"],\"articleSection\":[\"AngularJS with Examples\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\",\"url\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\",\"name\":\"Example of Angular Treeview using data from a JSON File\",\"isPartOf\":{\"@id\":\"https:\/\/jharaphula.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png\",\"datePublished\":\"2016-05-15T13:22:33+00:00\",\"dateModified\":\"2024-01-27T09:37:53+00:00\",\"description\":\"JSON is a lightweight data inter-exchange platform. Would you like to create a Angular Treeview using data from a JSON file? If so, Look at this example.\",\"breadcrumb\":{\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jharaphula.com\/example-angular-treeview-json\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage\",\"url\":\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png\",\"contentUrl\":\"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png\",\"width\":750,\"height\":436,\"caption\":\"Example of Angular Treeview using data from a JSON File\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jharaphula.com\/example-angular-treeview-json\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jharaphula.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Example of Angular Treeview using Data from a JSON File\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jharaphula.com\/#website\",\"url\":\"https:\/\/jharaphula.com\/\",\"name\":\"OneStop Shop\",\"description\":\"Blog for SEO Guest Posting, Digital Marketing or Home Remedies\",\"publisher\":{\"@id\":\"https:\/\/jharaphula.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jharaphula.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jharaphula.com\/#organization\",\"name\":\"OneStop Shop\",\"url\":\"https:\/\/jharaphula.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jharaphula.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jharaphula.com\/wp-content\/uploads\/2023\/10\/logo.jpg\",\"contentUrl\":\"https:\/\/jharaphula.com\/wp-content\/uploads\/2023\/10\/logo.jpg\",\"width\":409,\"height\":91,\"caption\":\"OneStop Shop\"},\"image\":{\"@id\":\"https:\/\/jharaphula.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/tajinweb\",\"https:\/\/x.com\/guestpostingopp\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/jharaphula.com\/#\/schema\/person\/129213d91cdcccd8f9396797c56e7dc3\",\"name\":\"Nibedita Panda\",\"description\":\"Mrs. Nibedita is a housewife. She is passionate about to write various information's depending upon the growing market trend. In our unit she takes care of many major releases. Her contribution is most valued for us.\",\"sameAs\":[\"https:\/\/jharaphula.com\"],\"url\":\"https:\/\/jharaphula.com\/author\/nibeditap\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Example of Angular Treeview using data from a JSON File","description":"JSON is a lightweight data inter-exchange platform. Would you like to create a Angular Treeview using data from a JSON file? If so, Look at this example.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jharaphula.com\/example-angular-treeview-json\/","og_locale":"en_US","og_type":"article","og_title":"Example of Angular Treeview using data from a JSON File","og_description":"JSON is a lightweight data inter-exchange platform. Would you like to create a Angular Treeview using data from a JSON file? If so, Look at this example.","og_url":"https:\/\/jharaphula.com\/example-angular-treeview-json\/","og_site_name":"OneStop Shop","article_publisher":"https:\/\/www.facebook.com\/tajinweb","article_published_time":"2016-05-15T13:22:33+00:00","article_modified_time":"2024-01-27T09:37:53+00:00","og_image":[{"width":750,"height":436,"url":"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png","type":"image\/png"}],"author":"Nibedita Panda","twitter_misc":{"Written by":"Nibedita Panda","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#article","isPartOf":{"@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/"},"author":{"name":"Nibedita Panda","@id":"https:\/\/jharaphula.com\/#\/schema\/person\/129213d91cdcccd8f9396797c56e7dc3"},"headline":"Example of Angular Treeview using Data from a JSON File","datePublished":"2016-05-15T13:22:33+00:00","dateModified":"2024-01-27T09:37:53+00:00","mainEntityOfPage":{"@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/"},"wordCount":555,"commentCount":0,"publisher":{"@id":"https:\/\/jharaphula.com\/#organization"},"image":{"@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage"},"thumbnailUrl":"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png","keywords":["AngularJS with Examples","Example of Angular Treeview","JSON Tutorial for beginners","Treeview Example","Treeview using Data from a JSON File"],"articleSection":["AngularJS with Examples"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jharaphula.com\/example-angular-treeview-json\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/","url":"https:\/\/jharaphula.com\/example-angular-treeview-json\/","name":"Example of Angular Treeview using data from a JSON File","isPartOf":{"@id":"https:\/\/jharaphula.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage"},"image":{"@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage"},"thumbnailUrl":"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png","datePublished":"2016-05-15T13:22:33+00:00","dateModified":"2024-01-27T09:37:53+00:00","description":"JSON is a lightweight data inter-exchange platform. Would you like to create a Angular Treeview using data from a JSON file? If so, Look at this example.","breadcrumb":{"@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jharaphula.com\/example-angular-treeview-json\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#primaryimage","url":"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png","contentUrl":"https:\/\/jharaphula.com\/wp-content\/uploads\/2016\/05\/treeview-using-json-records.png","width":750,"height":436,"caption":"Example of Angular Treeview using data from a JSON File"},{"@type":"BreadcrumbList","@id":"https:\/\/jharaphula.com\/example-angular-treeview-json\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jharaphula.com\/"},{"@type":"ListItem","position":2,"name":"Example of Angular Treeview using Data from a JSON File"}]},{"@type":"WebSite","@id":"https:\/\/jharaphula.com\/#website","url":"https:\/\/jharaphula.com\/","name":"OneStop Shop","description":"Blog for SEO Guest Posting, Digital Marketing or Home Remedies","publisher":{"@id":"https:\/\/jharaphula.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jharaphula.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jharaphula.com\/#organization","name":"OneStop Shop","url":"https:\/\/jharaphula.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jharaphula.com\/#\/schema\/logo\/image\/","url":"https:\/\/jharaphula.com\/wp-content\/uploads\/2023\/10\/logo.jpg","contentUrl":"https:\/\/jharaphula.com\/wp-content\/uploads\/2023\/10\/logo.jpg","width":409,"height":91,"caption":"OneStop Shop"},"image":{"@id":"https:\/\/jharaphula.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/tajinweb","https:\/\/x.com\/guestpostingopp"]},{"@type":"Person","@id":"https:\/\/jharaphula.com\/#\/schema\/person\/129213d91cdcccd8f9396797c56e7dc3","name":"Nibedita Panda","description":"Mrs. Nibedita is a housewife. She is passionate about to write various information's depending upon the growing market trend. In our unit she takes care of many major releases. Her contribution is most valued for us.","sameAs":["https:\/\/jharaphula.com"],"url":"https:\/\/jharaphula.com\/author\/nibeditap\/"}]}},"_links":{"self":[{"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/posts\/1518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/comments?post=1518"}],"version-history":[{"count":0,"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/posts\/1518\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/media\/1927"}],"wp:attachment":[{"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/media?parent=1518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/categories?post=1518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jharaphula.com\/wp-json\/wp\/v2\/tags?post=1518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}