ReferenceError: Angular is not defined Error - Mean
ReferenceError: Angular is not defined Error - Mean
我正在向 Thinkster.io 学习 MEAN,在第二步中,他在屏幕上显示了虚拟的 hello world 输出。当我尝试复制时,出现以下错误:
$ node app
F:\nodeProjects\flapperNews\app.js:3
angular.module('flapperNews')
^
ReferenceError: angular is not defined
at Object.<anonymous> (F:\nodeProjects\flapperNews\app.js:3:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
我的app.js如下:
angular.module('flapperNews', []).controller('MainCtrl', [
'$scope',
function($scope){
$scope.test = "Hello World";
}]);
和 index.html 是这样的:
<!DOCTYPE html>
<html>
<head>
<title>My Angular App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app ="flapperNews" ng-controller="MainCtrl">
</body>
</html>
我已经对这个错误进行了一些研究,解决方案是正确放置标签,但这并不能解决我的问题。
有人可以解释一下这里遗漏了什么以及如何启动服务器。
谢谢
您混淆了前端和后端,您正在尝试使用 nodejs 后端服务器执行 app.js
文件中的前端代码,就好像它是 nodejs 脚本一样。
您需要做的是使用网络浏览器为您的 angularjs 前端加载 html 和 js。
您可以只用网络浏览器打开 html 文件(双击 html 文件),或者您可以创建一个网络服务器并提供 html 和 js使用 apache、nginx 或 nodejs/express 服务器之类的文件。
在此处查看关于最后一个的更多信息 and here https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular
我正在向 Thinkster.io 学习 MEAN,在第二步中,他在屏幕上显示了虚拟的 hello world 输出。当我尝试复制时,出现以下错误:
$ node app
F:\nodeProjects\flapperNews\app.js:3
angular.module('flapperNews')
^
ReferenceError: angular is not defined
at Object.<anonymous> (F:\nodeProjects\flapperNews\app.js:3:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
我的app.js如下:
angular.module('flapperNews', []).controller('MainCtrl', [
'$scope',
function($scope){
$scope.test = "Hello World";
}]);
和 index.html 是这样的:
<!DOCTYPE html>
<html>
<head>
<title>My Angular App</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app ="flapperNews" ng-controller="MainCtrl">
</body>
</html>
我已经对这个错误进行了一些研究,解决方案是正确放置标签,但这并不能解决我的问题。 有人可以解释一下这里遗漏了什么以及如何启动服务器。 谢谢
您混淆了前端和后端,您正在尝试使用 nodejs 后端服务器执行 app.js
文件中的前端代码,就好像它是 nodejs 脚本一样。
您需要做的是使用网络浏览器为您的 angularjs 前端加载 html 和 js。
您可以只用网络浏览器打开 html 文件(双击 html 文件),或者您可以创建一个网络服务器并提供 html 和 js使用 apache、nginx 或 nodejs/express 服务器之类的文件。
在此处查看关于最后一个的更多信息