AngularJs: Form inside ng-if not accessible from controller
<p>I have a form inside <code>ng-if</code> directive. I want to check the form validation in controller using <code>$valid</code>. </p>

<pre><code>    &lt;div ng-if="paymentMethod == 12"&gt;
    &lt;form name="creditForm" id="cc-form" novalidate&gt;
        &lt;div class="form-group"&gt;
            &lt;label for="cardNumber"&gt;Card Number&lt;/label&gt;
            &lt;input type="text" autofocus class="form-control" name="card_number" ng-minlength="16" id="cardNumber" ng-model="creditCardNumber" required&gt;
            &lt;div class="red-text" ng-messages="creditForm.card_number.$error" ng-if="creditForm.card_number.$dirty || creditForm.$submitted"&gt;
                &lt;div ng-message="required"&gt;##global.Card_Num_Required##&lt;/div&gt;
                &lt;div ng-message="maxlength"&gt;##global.Card_Num_MinLength##&lt;/div&gt;
                &lt;div ng-message="minlength"&gt;##global.Card_Num_MaxLength##&lt;/div&gt;
                &lt;div ng-message="minlength"&gt;##global.Card_Num_Numeric ##&lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
</code></pre>

<p>and trying to check valid form in controller</p>

<pre><code>  if ($scope.$parent.creditForm.$valid) { 
      alert('valid');
      } else {
     alert('not valid');
 }
</code></pre>

<p>but the form is not accessible from controller.</p>