Printing a variable from a different view


#1

Currently I have a list of ionic items and when I click to each items individual page, I want to print that selected items id. To print the list I’m using a http.post request to get the content and a view with ng-repeat to iterate thro the values. My controller for the two views is

app.controller('contentCtrl', [ '$scope', '$state', function($scope, $state){
    $scope.contentCtrl = {};

     // I removed the http array

    $scope.contentCtrl.individual = function($scope, $id) {
        $scope.individualId = $id;
    };
}]);

The view for the list is

 <ion-list>
        <ion-item ng-repeat="individual in httparray" href="#/list/{{individual.id}}">
            <div ng-click="contentCtrl.individual({{ individual.id }})">
            ID: {{individual.id}} 
             </div>
        </ion-item>
 </ion-list>

and the view each item is linked to is

 <ion-content>
        <h1>Hello - {{ individualId }}</h1>
    </ion-content>

I’m sorry if it’s hard to read but this problem has been really bothering me. I tried using $stateParams with another ctrl but my http list would always crash. Any help really be very much appreciated.


#2

try to use $rootScope or service / factory

http://www.dotnet-tricks.com/Tutorial/angularjs/UVDE100914-Understanding-AngularJS-$rootScope-and-$scope.html