gpt4 book ai didi

javascript - Angular JS 不渲染 HTML

转载 作者:行者123 更新时间:2023-12-02 13:54:42 24 4
gpt4 key购买 nike

我是 Angular JS 新手。我编写了一个简单的 Angular 代码,但 HTML 未正确呈现或未评估表达式。请帮助我缺少什么。我正在使用 angular.min.js minified(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>

最佳答案

使用 ng-app 指令为您的应用程序设置根目录,并为您的应用程序创建一个 Controller ,您可以从中处理 $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>

关于javascript - Angular JS 不渲染 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com