(Solved in https://stackoverflow.com/a/19323406/462897 - Being a newbie (for stackoverflow) I can't answer my own question right now.)
The angular 1.2.14 compile docs say: '^ - Locate the required controller by searching the element's parents. Throw an error if not found.'
It seems to me that I not only get a controller on a parent element, but also controllers defined on the same element. Which isn't what is documented or what I need.
Any ideas what I'm doing wrong?
module.directive('viForm', [ViFormDirective]);
function ViFormDirective () {
return {
restrict: 'A',
require: ['form', 'viForm', '^viForm'],
controller: [ViFormController],
link: function ($scope, iElement, iAttrs, ctrls) {
// ctrls[0] ngForm
// ctrls[1] our ctrl 'viForm'
// ctrls[2] parentViFormCtrl '^viForm' - THIS is the same as ctrls[1]
ctrls[1].setNgForm(ctrls[0]);
$scope[ctrls[0].$name + 'ViForm'] = ctrls[1];
// todo check why the ^ parent prefix isn't working
if (ctrls[2] && ctrls[1] !== ctrls[2]) {
ctrls[1].setParentForm(ctrls[2]);
}
}
};
}
viForm?$element['inheritedData']('$' + require + 'Controller')to resolve the controller and this will include controllers on the same element. I've added a link to the correct solution to the OP.