I want to display two elements on a page controlled by different instances of the same controller , but I need to register some external information that will be unique (one "joystick" receives a set of identification properties as "player = one", while the other gets "player = two"). I'm not sure of the best way to get it for sure
Here is a general example of what I'm trying to accomplish:
<div ng-include src="'joystick/joy.tpl.html'" ng-controller="JoystickCtrl">...</div> <div ng-include src="'joystick/joy.tpl.html'" ng-controller="JoystickCtrl">...</div>
Should I:
Use directive?
<div ng-include src="'joystick/joy.tpl.html'" ng-controller="JoystickCtrl" player="one">...</div> <div ng-include src="'joystick/joy.tpl.html'" ng-controller="JoystickCtrl" player="two">...</div>
Use $ injector? (fyi - this may be an incorrect implementation)
<div ng-controller="DualJoyCtrl"> <div ng-include src="'joystick/joy.tpl.html'" ng-controller="joyOne" player="one">...</div> <div ng-include src="'joystick/joy.tpl.html'" ng-controller="joyTwo" player="two">...</div> </div> ----- .controller('DualJoyCtrl', function ($injector, JoystickCtrl, $scope, $rootScope) { $scope.joyOne = $injector.instantiate(JoystickCtrl, {$scope: $rootScope.$new(), player:"one"}); $scope.joyTwo = $injector.instantiate(JoystickCtrl, {$scope: $rootScope.$new(), player:"two"}); });
Or ... don't do it?
I understand that this seems like another seemingly flimsy message on the stack:
source share