angularjs - Share $Scope data between States -
i trying access parent state child. tried doesn't work.
angular.module('myapp').controller('comparectrl', ['$scope', function($scope) { $scope.test=$scope.$parent.services;
app.coffee
angular .module('myapp', ['nganimate', 'ngcookies', 'ngresource' , 'ui.router', 'ngsanitize', 'ngtouch']) .config ($stateprovider) -> $stateprovider.state('home', url: "/" templateurl: "home.html" ).state('services', url: "/services" templateurl: "services/list.html" ).state('services.detail', url: "/detail/" templateurl: "detail.html" ).state('services.compare', url: "/compare/" templateurl: "compare.html" )
ui-router supports data (model) sharing among state families. detailed explanation found here
how share $scope data between states in angularjs ui-router?
where can see, need introduce model, cluster, reference object.
// controller of parent state 'services' .controller('servicesctrl', ['$scope', function($scope) { $scope.model = { prop1 : value1, ...}; }])
because each child state prototypically inherit reference $scope.model... can access in child state controller
.controller('servicechildctrl', ['$scope', function($scope) { $scope.model.prop1 = differentvalue; }])
check in action in this working plunker
Comments
Post a Comment