0

我有一个我认为是非常基本的 Angular JS 问题。有人可以向我解释为什么表达。

{{hi}}

没有评估,我收到以下错误:

Uncaught TypeError: angular.module is not a function

这是plunker,代码如下。

html:

<!DOCTYPE html>
<html>

  <head>
    <script src="https://code.angularjs.org/2.0.0-alpha.20/angular2.sfx.dev.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-app="expressionExample">

    <div ng-controller="ExampleController" class="expressions">
    {{hi}}
</div>

    <cmp></cmp>
  </body>

</html>

js:

angular.module('expressionExample', [])
.controller('ExampleController', ['$scope', function($scope) {
  var exprs = $scope.exprs = [];
  $scope.expr = '3*10|currency';
  $scope.hi= 'hi';
  $scope.addExp = function(expr) {
    exprs.push(expr);
  };

  $scope.removeExp = function(index) {
    exprs.splice(index, 1);
  };
}]);
4

2 回答 2

0

您正在使用 Angular 2.0 参考

一旦我更新了对 1.4.0-rc1 的引用

它工作正常。这是更新的plunker

<!DOCTYPE html>
<html>

  <head>
    <script data-require="angular.js@1.4.0-rc.1" data-semver="1.4.0-rc.1" src="https://code.angularjs.org/1.4.0-rc.1/angular.js"></script>
    <script src="main.es6.js"></script>
  </head>

  <body ng-app="expressionExample">
    <div ng-controller="ExampleController" class="expressions">
    {{hi}}
    </div>
    <cmp></cmp>
  </body>

</html>
于 2015-05-05T21:10:06.593 回答
0

您好,您在代码中使用 Angular 2.0 插件

您已经编写了 angular 1 语法,因此您必须在 html 中编写 angular 1.4.0 插件,然后它可能会完美运行

于 2017-08-08T13:12:56.837 回答