0
    var parent = angular.module('parent', ['swxSessionStorage']);

    parent.controller('parent', [

        $scope.idMenu = [{
                label : "id1",
                value : 1
            }]

$scope.name=[abc,def];
     /**
         * Calling child controller
         */

        var childView = $scope.$new(true);
        $controller('child',{$scope:childView});
        $scope.someMetod = function(){
            childView.getChildData();
        }
        }


        --------------
    parent.controller('child', [
    $scope.getChildData = function(){
        $scope.idMenu.value
    }

I'm not able to access parent $scope.idMenu in Child controller?

But Im able to access $scope.name,which is just an array,but Im not able to access JsonArray.

What could be the reason?

1
  • 1
    it's an array so use $scope.idMenu[0].value Commented Feb 3, 2016 at 7:05

2 Answers 2

1

In parent controller

$scope.$broadcast('event_name', function (){ 
//action on event     
}); 

In child controller

$scope.$on('event_name', function () {   
//data required to pass in parent controller      
});
Sign up to request clarification or add additional context in comments.

Comments

0

The best way would be to use a service.

app.service('dataService', function() {
  var dataList = [];

  function addData(data) {
    dataList.push(data);
  };

  function getData() {
    return dataList;
  };

  return {
    add: addData,
    get: getData
  };
});

In your parent controller, store the information via the service:

app.controller('parent', function($scope, dataService) {
  $scope.addMyData = function(obj) {
    dataService.addData(obj);
  };
});

And in the child controller, retrieve the information via the service:

app.controller('child', function($scope, dataService) {
  $scope.products = dataService.getData();
});

You cannot inject $scope into the service but you can store data.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.