0

(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]);
        }
      }
    };
  }
2
  • Is there a parent directive with the same name viForm? Commented Mar 24, 2014 at 14:22
  • Angular js doc is misleading. '^' uses $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. Commented Mar 24, 2014 at 14:28

0

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.