【问题标题】:Reference Error - angular not defined参考误差 - 角度未定义
【发布时间】:2016-11-17 02:27:44
【问题描述】:

以下是我的 app.html - 我将在其中注入其他部分视图的模板,

<html ng-app="billApp">
<head>
  <!-- SCROLLS -->
  <!-- load bootstrap and fontawesome via CDN -->
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.0/css/font-awesome.css" />

  <!-- SPELLS -->
  <!-- load angular via CDN -->
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
      <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>
  <script src="script.js"></script>
</head>

<!-- define angular controller -->
<body ng-controller="mainController">

...

<!-- MAIN CONTENT AND INJECTED VIEWS -->
<div id="main">
    {{ message }}

    <!-- angular templating -->
    <!-- this is where content will be injected -->
</div>
</body>
</html>

这是 script.js 文件,它是应用程序的控制器,

// script.js

// create the module and name it scotchApp
var billApp = angular.module('billApp', []);

// create the controller and inject Angular's $scope
billApp.controller('mainController', function($scope) {

    // create a message to display in our view
    $scope.message = 'Everyone come and see!';
});

当我尝试使用我的命令行运行 script.js 文件时

  1. 将目录切换到nodejs目录

  2. 输入'node path-of-the-project-file\script.js'

这会引发以下错误, var billApp = angular.module('billApp', []); 未定义参考误差角度。

我不知何故错过了一些基本细节。如果有人可以在这里给我一些指示,那就太好了

【问题讨论】:

标签: javascript angularjs node.js


【解决方案1】:

你需要在 Angular 脚本之前包含 jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

【讨论】:

    【解决方案2】:

    替换

    &lt;script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular-resource.min.js"&gt;&lt;/script&gt;

    符合

    &lt;script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular-resource.min.js"&gt;&lt;/script&gt;

    因为它没有获得ngResource 所需的库。

    在开头加入这一行

    &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"&gt;&lt;/script&gt;

    【讨论】:

      猜你喜欢
      • 2016-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2023-04-01
      相关资源
      最近更新 更多