【问题标题】:ReferenceError: Angular is not defined Error - MeanReferenceError:未定义角度错误 - 平均值
【发布时间】:2017-03-12 03:12:47
【问题描述】:

我正在从 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>

我已经对此错误进行了一些研究,解决方案是正确放置标签,但这并不能解决我的问题。 有人可以解释一下这里遗漏了什么以及如何启动服务器。 谢谢

【问题讨论】:

    标签: javascript angularjs mean-stack


    【解决方案1】:

    您将前端与后端混淆,您试图使用 nodejs 后端服务器执行 app.js 文件中的前端代码,就好像它是一个 nodejs 脚本一样。

    您需要做的是使用网络浏览器为您的 angularjs 前端加载 html 和 js。

    您可以使用网络浏览器打开 html 文件(双击 html 文件),或者您可以创建一个网络服务器并使用 apache、nginx 或 nodejs/express 服务器等服务提供 html 和 js 文件。

    在Node js as http server and host angularJS SPA 和https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular 上查看最后一个的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-08
      • 2019-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多