我是Angular JS的新手。我写了一个简单的Angular代码,但HTML没有正确呈现,或者表达式没有得到评估。请帮助我缺少什么。我正在使用angular.min.js缩小(1.6)。
<!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 :(得分:2)
使用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>