vivek
vivek

Reputation: 393

Show corresponding data in modal popup in angular modal instance controller

I have a json data like below

var data = [{
    id: 1,
    name: 'mobile',
    parentid: 0
  }, {
    id: 2,
    name: 'samsung',
    parentid: 1
  }, {
    id: 3,
    name: 'moto',
    parentid: 1
  }, {
    id: 4,
    name: 'redmi',
    parentid: 1
  }, {
    id: 5,
    name: 'honor',
    parentid: 1
  }, {
    id: 6,
    name: 'tv',
    parentid: 0
  }, {
    id: 7,
    name: 'tv1',
    parentid: 6
  }, {
    id: 8,
    name: 'tv2',
    parentid: 6
  }, {
    id: 9,
    name: 'tv3',
    parentid: 6 
  }, {
    id: 10,
    name: 'tv4',
    parentid: 6
  }, {
    id: 11,
    name: 'tv5',
    parentid: 6
  }];

I have pushed all data into array and pushed only parentid zero into another array in my controller when I click button I want to show corresponding subcategories in modal popup using modal instance controller my plunkr link is below. http://plnkr.co/edit/VBN17osdHx4AAMzNnPSe?p=preview?

Upvotes: 0

Views: 68

Answers (1)

AlexanderDrysdale
AlexanderDrysdale

Reputation: 64

Use $rootScope to spread data across its children i.e. the modal, from there you can manipulate it to use subcategories using filters.

$rootScope.data = [{...}]
$rootScope.SelectedId = 0;

alternatively you can use the code below to access parent data but it must live within a scope

$scope.$parent.data

Upvotes: 1

Related Questions