Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs if else condition using json array
    primarykey
    data
    text
    <p>I am using Angularjs and I am populating data from json file. I am using ng-repeat to display data. There is a Categories, subcategories and Products. Some Categories had subcategories some categories had some products. I am trying to write condition like if categories had subcategories display subcategories and if has product then display products.</p> <pre><code>[{ "category":"Cables", "subCategories":[ { "subCategory":"Sub Category 1" }, { "subCategory":"Sub Category 2" } ] }, { "category":"Wallplates &amp; Boxes", "subCategories":[ { "subCategory":"Sub Category 6" }, { "subCategory":"Sub Category 7" } ] }, { "category":"Media Distribution", "products":[ { "proTitle":"Product 1" }, { "proTitle":"Product 2" } ] }] </code></pre> <p>The controller is below.</p> <pre><code>var app = angular.module('analytics', []); app.controller ('categoryCtrl', function ($scope, $http){ $http.get('json/category_data_new.json').success(function(data) { $scope.chartValues = data; }); </code></pre> <p>});</p> <p>I am using below code to display Categories and under subcategories </p> <pre><code>&lt;ul class="nav"&gt; &lt;li ng-repeat="chartValue in chartValues"&gt; &lt;span ng-click="loadRecord(chartValue, $index)"&gt; {{chartValue.category}} &lt;/span&gt; &lt;ul ng-show="chartValue.subCatList"&gt; &lt;li ng-repeat="item in chartValues[$index].subCategories"&gt; &lt;span ng-click="loadSubRecord(item, $index)"&gt; {{item.subCategory}} &lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>if any one have any idea how do this? please suggest. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload