2016-11-24 110 views
0

我是Angular JS的新手。我寫了一個簡單的Angular代碼,但是HTML沒有正確渲染,或者表達式沒有得到評估。請幫助我失去了什麼。我正在使用angular.min.js縮小(1.6)。Angular JS不呈現HTML

<!DOCTYPE html> 
<html ng-app> 
    <head> 
     <script src="js/angular.min.js"></script> 
     <script> 
      function MyFirstCtrl($scope) { 
      var employees = ['Catherine Grant', 'Monica Grant', 
       'Christopher Grant', 'Jennifer Grant']; 

      $scope.ourEmployees = employees; 
      }; 
     </script> 
    </head> 
    <body ng-controller='MyFirstCtrl'> 
     <h2>Number of Employees: {{ ourEmployees.length}}</h2>  
    </body> 
</html> 
+0

'NG-controller'? 'var app'? 'app.controller'? – Rayon

+0

閱讀角度docs開始..https://docs.angularjs.org/tutorial – user2427829

+0

點擊開始學習http://www.w3schools.com/angular/default.asp –

回答

2

設置root爲您的應用與ng-app指令,併爲您的應用程序控制器,從中可以處理$scope

var app = angular.module("ng-app", []); 
 
app.controller("myCtrl", function($scope) { 
 
    var employees = ['Catherine Grant', 'Monica Grant', 'Christopher Grant', 'Jennifer Grant']; 
 
    $scope.ourEmployees = employees; 
 

 
});
<!DOCTYPE html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="ng-app"> 
 
<div ng-controller="myCtrl"> 
 
    <h2>Number of Employees: {{ ourEmployees.length}}</h2> 
 
    </div> 
 
</div>

+0

謝謝。這有幫助。 :) – Rohit