角度误差:[$ injector:modulerr]全局控制器

时间:2015-11-12 09:08:02

标签: javascript html angularjs

我正在做一个Angularjs课程,我必须做一个练习,但对我来说这样做是不可能的:

app.js:

function OcultarController($scope) {
  $scope.oculto = true;

  $scope.cambioColor = function() {
    $scope.oculto = !$scope.oculto;
  };
}

angular.module('app', []);
angular.module('myModule').config(['$controllerProvider', function($controllerProvider) {
  $controllerProvider.allowGlobals();
}]);

的index.html

<html ng-app="app">
  <head>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body>
    <div ng-controller="OcultarController">
      <p style="background-color:red;" ng-show="oculto">ROJO</p>
      <p style="background-color:green;" ng-hide="oculto">VERDE</p>
      <button ng-click="cambioColor()">Cambiar color</button>
    </div>
  </body>
</html>

我试着让它工作,但我不能,我是Angularjs的新手,我不知道我是否做得好,这个练习只是告诉我复制过去的代码,但是什么我觉得并不那么容易。

控制台告诉我这个(我正在使用firefox):

Error: [$injector:nomod] http://errors.angularjs.org/1.3.15/$injector/nomod?p0=myModule angular.min.js:6:417
"Error: [ng:areq] http://errors.angularjs.org/1.3.15    /ng/areq?p0=OcultarController&p1=not%20a%20function%2C%20got%20undefined
R/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:6:417
Rb@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:19:1
sb@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:20:78
Fe/this.$get</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:75:396
B/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:57:100
r@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:7:406
B@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:56:471
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:51:335
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:51:352
g@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:51:352
D/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:50:444
uc/d/</<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15   /angular.min.js:18:4
Pe/this.$get</n.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:126:11
Pe/this.$get</n.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:126:236
uc/d/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:17:477
e@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:36:313
uc/d@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:17:1
uc@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:18:179
Jd@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:17:1
@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:250:429
a@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:164:283
lf/c@https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js:32:384
"

3 个答案:

答案 0 :(得分:1)

首先,你在这里创建两个模块(这不一定是个问题,但在你的情况下,我猜你不需要那个):

angular.module('app', []);
angular.module('myModule').

将其更改为:

var app = angular.module('app', []);
app.config(['$controllerProvider', function($controllerProvider) {
  $controllerProvider.allowGlobals();
}]);

app.controller('OcultarController', OcultarController);

答案 1 :(得分:0)

你必须告诉你的应用程序&#34;它应该加载你的模块&#34; myModule&#34;。

更改

/Volumes/HD/Repos

angular.module('app', []);

并将其移至文件的末尾。

答案 2 :(得分:0)

普兰克:http://plnkr.co/edit/Vx5FuIemuj636r3ixzWt?p=preview

$dbh->do("LISTEN abc");
$dbh->do("LISTEN def");

## Hang around until we get the message we want
LISTENLOOP: {
  while (my $notify = $dbh->pg_notifies) {
    my ($name, $pid, $payload) = @$notify;
    print qq{I received notice "$name" from PID $pid, payload was "$payload"\n};
    ## Do something based on the notice received
  }
  $dbh->ping() or die qq{Ping failed!};
  $dbh->commit();
  sleep(5);
  redo;
}