I am creating angular -app with ui-router where I have a parent view and a child view.
routerApp.config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/home'); $stateProvider .state('home', { url: '/home', templateUrl: '/views/home/home.html', controller: 'HomeController' }) .state('new-assignment', { url: '/new-assignment', templateUrl: 'new-assignment.html', controller: 'AssignmentController' }) .state('new-assignment.new-client', { url: '/new-client', templateUrl: 'new-client.html', controller: 'ClientController' }) ; });
Children's view is used (among other things) to create a new client. Thus, by clicking "create a new customer" in the main view. The status is changed to "new-assign.new-client" and a side view is displayed.
When the client is created, I want to go to the parent view of the βnew assignmentβ and pass on the information with which client was just created.
A parent view can still have data in its own form (to create an assignment) and, of course, should not be affected.
I can detect the change through the $ stateChangeSuccess event:
routerApp.controller('AssignmentController', function($scope, Assignment, Client, $log) { $scope.clients = Client.clients; $scope.$on('$stateChangeSuccess', function (e, toState, toParams, fromState, fromParams){ $log.log(fromState.name + ' -> ' + toState.name); $log.log('toParams '); $log.log(toParams); $log.log('fromParams '); $log.log(fromParams); }); });
I tried to pass information through
$state.go('^', data);
but without success ...
But I do not understand how to pass data to the parent view. Any ideas?
javascript angularjs angular-ui-router
mraxus
source share