Share $Scope data between States

后端 未结 1 871
攒了一身酷
攒了一身酷 2021-01-24 09:40

I am trying access the parent state from a child. I tried this but it doesn\'t work.

angular.module(\'myApp\').controller(\'compareCtrl\', [\'$scope\',
    funct         


        
相关标签:
1条回答
  • 2021-01-24 10:13

    UI-Router supports data (Model) sharing among state families. The detailed explanation could be found here

    How do I share $scope data between states in angularjs ui-router?

    Where we can see, that we need to introduce a Model, a cluster, a reference object.

    // controller of the parent state 'services'
    .controller('ServicesCtrl', ['$scope',
        function($scope) {
            $scope.Model = { prop1 : value1, ...};
    }])
    

    Because now each child state will prototypically inherit that reference to $scope.Model... we can access it in any child state controller

    .controller('ServiceChildCtrl', ['$scope',
        function($scope) {
            $scope.Model.prop1 = differentValue;
    }])
    

    Check it in action in this working plunker

    0 讨论(0)
提交回复
热议问题