Angular注入器自调用函数语法错误

Angular injector error with self invocation function syntax

本文关键字:语法 错误 函数 调用 注入器 Angular      更新时间:2023-09-26

我已经创建了一个基本的angular应用程序,带有自调用函数

(function(){})

当我运行应用程序时,它抛出注入器错误,如果我删除上述代码,它工作正常,我已经通过了许多网站,但无法解决这个问题,为什么会发生这种情况,我无法理解。

HTML:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
    <script src="script.js"></script>
  </head>
  <body ng-app="myApp">
    <h1>Hello Plunker!</h1>
  </body>
</html>

script.js:

(function(){
  angular.module("myApp", [])  
});
演示

你需要像这样,

(function(){
  angular.module("myApp", [])  
})();