I can't seem to figure out how to make controller one know about controller two...?
controller1
rows & columns + edit button
controller2
rows & columns
modal popup
field 1...n where one or more is a <select><option...>list based on the rows in controller2
I suspect it has to do with $injectors but that is only a guess and requires a lot more reading to understand this concept.
Any suggestions would be welcome.
--hm--
You emit messages with somehting like this in the first controller:
$scope.onCellChange = function () {
cellService.selectedCell = $scope.selection;
// Send message to HeaderController
$scope.$root.$emit("cellSelected", $scope.selection.CellDefID);
};
Then on the receiving controller you have a method that picks up the message using $on:
$scope.$root.$on("cellSelected", function (e, id) {
$scope.processing = true; // progress display
cellService.loadQueues(id)
.success(function(result) {
$scope.queues = result;
})
.finally(function() {
$scope.processing = false; // stop progress
});
});
+++ Rick ---
I have two or more controllers on a page, each is listing rows and columns from my VFP table. I have an edit button on each row that pops up a modal dialog. Some of the edit fields on the popup combine the data contained in the separate controllers via select dropdown option groups.
I can't seem to figure out how to make controller one know about controller two...?
controller1
rows & columns + edit button
controller2
rows & columns
modal popup
field 1...n where one or more is a <select><option...>list based on the rows in controller2
I suspect it has to do with $injectors but that is only a guess and requires a lot more reading to understand this concept.
Any suggestions would be welcome.
West Wind Technologies
Making waves on the Web
from Maui
thanks for this pointer, I'm sure it will come up soon enough. <g>
--hm
Easiest way to do this is to use $scope.$emit() and $scope.$on() to pass messages from one controller to another.
You emit messages with somehting like this in the first controller:
$scope.onCellChange = function () {
cellService.selectedCell = $scope.selection;
// Send message to HeaderController
$scope.$root.$emit("cellSelected", $scope.selection.CellDefID);
};
Then on the receiving controller you have a method that picks up the message using $on:
$scope.$root.$on("cellSelected", function (e, id) {
$scope.processing = true; // progress display
cellService.loadQueues(id)
.success(function(result) {
$scope.queues = result;
})
.finally(function() {
$scope.processing = false; // stop progress
});
});
+++ Rick ---
I have two or more controllers on a page, each is listing rows and columns from my VFP table. I have an edit button on each row that pops up a modal dialog. Some of the edit fields on the popup combine the data contained in the separate controllers via select dropdown option groups.
I can't seem to figure out how to make controller one know about controller two...?
controller1
rows & columns + edit button
controller2
rows & columns
modal popup
field 1...n where one or more is a <select><option...>list based on the rows in controller2
I suspect it has to do with $injectors but that is only a guess and requires a lot more reading to understand this concept.
Any suggestions would be welcome.
--hm--
Not sure what you mean. $scope instances aren't visible to each other unless they are in a hierarchy. Nested child $scopes inherit the parent $scope properties, but sibling or completely unrelated controllers can't see each other's $scope.
For those cases $emit() and $on() are the way to go. It's also not just about getting the value over there - it's also about notifying the other controller that something needs to happen. Since controller code runs only once when activated, you still need a way to notify the other controller typically when a value is updated and the $emit()/$on sequence is a nice way of doing this.
+++ Rick ---
West Wind Technologies
Making waves on the Web
from Maui