2016-06-29 23 views
1

角控制器無法與index.html連接,項目使用安裝了node.js的http-server運行。無法運行angularjs文件控制器錯誤

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>` 
+0

做出 'ngClassifieds' 模塊的使用,棱角分明。模塊(「ngClassifieds」,[]).. – Ajay

回答

0

你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'}; 
       }; 
        }]();