AngularJs - Module defined but still gets "not available" error
<p>I'm trying to build password matching mechanism using angular <code>directive</code> and seems like I'm missing something. I defined <code>ng-app</code> and <code>ng-controller</code> but I still get an error message stating the the <code>module</code> is not defined.
<br><br>
Jsfiddle <a href="https://jsfiddle.net/7ncx3fyL/1/" rel="nofollow">here</a>.</p>

<pre><code>Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
</code></pre>

<p>HTML:</p>

<pre><code>&lt;div ng-app="myApp"&gt;
  &lt;div class="row" ng-controller='Ctrl'&gt;
    &lt;form name="form1"&gt;
      &lt;div class="col-xs-12 col-sm-6 col-md-6"&gt;
        &lt;div class="form-group"&gt;
          &lt;input type="password" ng-model="login.password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="5"&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="col-xs-12 col-sm-6 col-md-6"&gt;
        &lt;div class="form-group"&gt;
          &lt;input ng-model="login.verify" type="password" name="verify" placeholder="Confirm Password" nx-equal="login.password" class="form-control input-lg" tabindex="6"&gt;
          &lt;div class="error" ng-show="form1.verify.$error.nxEqual"&gt;Passwords are not equal&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/form&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>JS:</p>

<pre><code>var app = angular.module("myApp", []);
app.controller("Ctrl", function($scope){

});
app.directive('nxEqual', function() {
  return {
    require: 'ngModel',
    link: function(scope, elem, attrs, model) {

      if (!attrs.nxEqual) {
        console.error('nxEqual expects a model as an argument!');
        return;
      }
      scope.$watch(attrs.nxEqual, function(value) {
        model.$setValidity('nxEqual', value === model.$viewValue);
      });
      model.$parsers.push(function(value) {
        var isValid = value === scope.$eval(attrs.nxEqual);
        model.$setValidity('nxEqual', isValid);
        return isValid ? value : undefined;
      });
    }
  };
});
</code></pre>