【发布时间】:2017-02-27 02:36:03
【问题描述】:
我是 Angular 的新手,正在尝试做一个简单的 Hello World。请在下面找到我的源文件:
<html >
<head>
<script src="./node_modules/angular/angular.js"></script>
<title>ngClassifieds</title>
</head>
<body ng-app="ngClassifieds">
<div>
<label>Name:</label>
<input type="text" ng-init="yourName = 'oie'" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
..\ngClassifieds\scripts\app.js
angular.module("ngClassifieds",[]);
当前存在的文件结构(使用 npm 创建)
└───ngClassifieds
│ index.html
│ package.json
│
├───css
├───node_modules
│ ├───angular
│ │ angular-csp.css
│ │ angular.js
│ │ angular.min.js
│ │ angular.min.js.gzip
│ │ angular.min.js.map
│ │ bower.json
│ │ index.js
│ │ LICENSE.md
│ │ package.json
│ │ README.md
我目前面临两个问题:
- 如果我在 index.html 文件中将 ng-app 设置为 ng-app="ngClassifieds",Angular 将停止工作(请参阅下面的输出)
- 如果我使用 \ngClassifieds\node_modules\angular\angular.js 文件,而不是 https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js,它将停止工作(见下面的输出)
而如果我删除 ng-app 参数并改用 https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js,它会按预期工作:
这是有效的index.html:
<html >
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<title>ngClassifieds</title>
</head>
<body ng-app>
<div>
<label>Name:</label>
<input type="text" ng-init="yourName = 'oie'" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
【问题讨论】:
-
你的
ng-controller呢? -
我没有。我正在按照这里描述的步骤school.scotch.io/getting-started-with-angularjs-1x/…
标签: javascript angularjs npm