[英]Can't get simple AngularJS app to work
I basically copied this code from a video tutorial from the official site. 我基本上从官方网站的视频教程中复制了此代码。 I wish '4' were shown on the screen, but it keeps showing '{{ totalTodos }}'.
我希望屏幕上显示“ 4”,但它一直显示“ {{totalTodos}}”。 Here index.js:
这里index.js:
function TodoCtrl($scope) {
$scope.totalTodos = 4;
}
And here index.html: 还有index.html:
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</head>
<body>
<div ng-controller="TodoCtrl">
{{ totalTodos }}
</div>
</body>
</html>
It's good practice to start correctly if you are newbie in angularJs. 如果您是angularJs的新手,那么正确启动是一个好习惯。 Start by creating
module
and give it any name. 首先创建
module
并为其命名。 I used app
as a module name and then your controller and so on .. 我使用
app
作为模块名称,然后使用您的控制器等等。
angular.module("app", []).controller("TodoCtrl", function ($scope) { $scope.totalTodos = 4; });
<html ng-app="app"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script> <script type="text/javascript" src="index.js"></script> </head> <body> <div ng-controller="TodoCtrl"> {{ totalTodos }} </div> </body> </html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.