正如标题所暗示的,我正在尝试自学 Angular.js,但我遇到了意想不到的令人沮丧的障碍......我什至无法让变量在网页上正确显示!
<!DOCTYPE html>
<html ng-app>
<head>
<title>Lets test this out?</title>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
Write your name in the text box!
<input type="text" ng-model="sometext" />
<h1>Hello {{ sometext }}</h1>
</body>
</html>
如果有人能告诉我我做错了什么,我将不胜感激,因为我已经将头撞在 table 上一个小时了,并在谷歌上搜索了这个问题,但我不明白为什么它不起作用。
最佳答案
检查您的 Angular 引用是否已正确加载。尝试将 ng-app 添加到你的 body 标签中
演示
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app>
Write your name in the text box!
<input type="text" ng-model="sometext" />
<h1>Hello {{ sometext }}</h1>
</body>
关于javascript - Angular 变量未在网页上正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45301411/