0

I have two separate controllers on one page. One of them broadcasts an event and the other listens for it. When the one that listens receives the event, it changes it's scope variable and then prints the page. For some reason, I see the scope applying but I don't see it apply to the page.

$scope.$on('valuesUpdated', function(){
    $scope.Name = dataGrabber.Name;
    $scope.Address = dataGrabber.Address;       
    window.print();
});
1
  • There is not enough data to detect the issue. Please post all relevant code or better try to reproduce this behavior in Fiddle/Plunker. Commented Nov 6, 2014 at 21:41

1 Answer 1

1

Given the information you provided, I think it's the known scope hiding issue.

Scope inheritance is normally straightforward, and you often don't even need to know it is happening... until you try 2-way data binding (i.e., form elements, ng-model) to a primitive (e.g., number, string, boolean) defined on the parent scope from inside the child scope. It doesn't work the way most people expect it should work. What happens is that the child scope gets its own property that hides/shadows the parent property of the same name. This is not something AngularJS is doing – this is how JavaScript prototypal inheritance works. More about it here...

The solution will be to use objects notation:

$scope.data.Name

Or the Controller As notation for controllers.

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

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.