簡體   English   中英

ReferenceError:未定義角度錯誤-均值

[英]ReferenceError: Angular is not defined Error - Mean

我正在從Thinkster.io學習MEAN,第二步,他在屏幕上顯示了虛擬的hello世界。 當我嘗試復制時,出現以下錯誤:

$ 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腳本一樣。

您需要做的是使用Web瀏覽器為angularjs前端加載html和js。

您可以使用網絡瀏覽器打開html文件(雙擊html文件),也可以創建網絡服務器並使用apache,nginx或nodejs / express服務器等服務於html和js文件。

在最后一個中查看更多信息,這里的Node js作為http服務器並托管angularJS SPA,並且在這里https://scotch.io/tutorials/creating-a-single-page-todo-app-with-node-and-angular

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM