0

I have two controllers in my app TimelineController and ReservationModalController. I want to call TimelineController from ReservationModalController and pass variable value. I'm trying to that: this is my app.js

$stateProvider
// Timeline
    .state('timeline', {

    url: '/timeline',
    controller: 'TimelineController',
    templateUrl: 'assets/partials/timeline.html',
    params: {
        operation: 'false'
    }

})

this is TimelineController

$scope.operation = $state.current.params.operation;

and this is ReservationModalController :

$scope.edit = function() {
  $modalInstance.close();
  $state.go('timeline', {
    operation: 'true'
  });
};

At the first time variable is initialized. But when I click the button and ReservationModalController and it's method edit is called TimelineController and it's variable $scope.operation does not change.

Please help me what is wrong?

2
  • take a look at this: stackoverflow.com/questions/24842597/… I'm guessing you want your controllers to be able to talk to each other. Commented Feb 1, 2016 at 20:42
  • I know this solution but in my case, i don't want to use this. In angular i can use $state.go() function but does not working, so i'm interesting why? Commented Feb 2, 2016 at 6:34

2 Answers 2

0

Probably, you should $broadcast to communicate between controllers here so they are not as tightly bound to each other. $rootScope.$broadcast is sending an event through the application scope. Any children scope of that app can catch it using a simple: $scope.$on().

It is especially useful to send events when you want to reach a scope that is not a direct parent (like two controllers of which is none a parent for the other for example).

There's a fiddle that shows how to do this: https://jsfiddle.net/VxafF/

Sign up to request clarification or add additional context in comments.

1 Comment

Your script in my browser does not working. Also i know this solution but i don't want to use this.
0

You could also try nesting your TimeLineController inside your ReservationModalController. That way you can use $scope inheritance to communicate between controllers.

Read this:http://www.angularjshub.com/examples/basics/nestedcontrollers/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.