javascript - 无法运行 angularjs 文件 Controller 错误

标签 javascript jquery html angularjs

Angular Controller 无法与index.html连接,该项目使用安装了node.js的http服务器运行。

classifieds.js

      `(function() {
             "use strict";
            angular
            .module("ngClassifieds")
             .controller("ClassifiedsCtrl", ['$scope', function($scope) {
           $scope.name ={text: 'Asif'};
            };
                }]();`

index.html

            `<!DOCTYPE html>
              <html>
             <head>
                <title>ngClassifieds</title>
             </head>
        <body ng-app="ngClassfieds" ng-controller="ClassifiedsCtrl">

       <input type="text" placeholder="Whats your name" ng-model="name" >
       <h1>{{greeting.text}}</h1>
         <script src="node_modules/angular/angular.min.js"> </script>
         <script src="scripts/app.js"></script>
      <script src="components/classifieds.js"></script>
       </body>
        </html>`

最佳答案

您的classified.js 文件应如下所示

angular.module("ngClassifieds",[])
     //you should pass an empty array in every module NOTE:inside the array it can the injected field

    (function() {
                 "use strict";

                 .controller("ClassifiedsCtrl", ['$scope', function($scope) {
               $scope.name ={text: 'Asif'};
                };
                    }]();

关于javascript - 无法运行 angularjs 文件 Controller 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38092852/

相关文章:

用 python 编写的类似 Javascript 的 TCP 套接字客户端?

javascript - 当滚动条到达特定位置时动画 div

jquery - 来自 Google 的 jQuery 图像建议

javascript - 灯箱不调出放大的 img,只是白色框

javascript - 按下一个按钮并更改页面上其他地方的框的颜色

python - Sentence.split 获取网站页面

javascript - 如何在handsontable中显示百分比而不是比率?

javascript - 匹配字符串前面包含 10 个或更少非空白字符的字符串,忽略空白字符

javascript - 如何将数据从输入传递到自定义服务?

javascript - Ajax 加载内联 javascript