How can I check an ng-included form's validity from the parent scope?

后端 未结 2 1841
滥情空心
滥情空心 2020-12-25 12:06

I have a subform that is shared among multiple views in my app. In one view, this subform is displayed alone with a back/continue button at the bottom that leads the user to

2条回答
  •  情书的邮戳
    2020-12-25 12:37

    The child scope created when you use ng-include is hiding the form functions from the parent.

    In addition to using a directive, you can also add an object in the parent, but it's important to set the name of the form to an object with a property like so:

    and in the parent controller

    $scope.myFormHolder = {};
    

    then the following should work:

    $scope.myFormHolder.myForm.$pristine
    

    This way when the form is evaluated, myForm.$valid will get set on the parent. I believe I asked this same question: Why form undefined inside ng-include when checking $pristine or $setDirty()?

提交回复
热议问题