ngRoute引用错误

时间:2015-08-07 05:18:07

标签: html angularjs

如图所示我试图使用控制器来检索JSON文件,但错误

  

“由于以下原因导致实例化模块getJson失败:   错误:[$ injector:nomod] http://errors.angularjs.org/1.2.23/ $ injector / nomod?p0 = get ...“

继续弹出。我已经在这里引用了角度依赖ngRoute。

的index.html

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-route.js"></script>
<script src="../public/javascripts/processJson.js"></script>
</head>
<body>    
   <div ng-app="getJson"><div ng-controller="controller1">
      <div ng-repeat="post in posts">
       <div ng-switch-when="text"><input type="text" id="{{post.id}}" ng-model="post.value" placeholder="{{post.placeholder}}">
 </div>
  </div>
  </div>
</div>
 </body>
 </html>

控制器

var getJson = angular.module('getJson', []).controller('controller1', function ($scope, $http) {
var url = "../../routes/fields.js";
console.log(url);
$http.get(url).success(function (data) {
    $scope.posts = data;
  });

 });

1 个答案:

答案 0 :(得分:0)

您已添加了angular-route文件,但尚未将其作为依赖项添加到模块中。 请使用

var getJson = angular.module('getJson', ['ngRoute']).controller('controller1', function ($scope, $http) {
var url = "../../routes/fields.js";
console.log(url);
$http.get(url).success(function (data) {
    $scope.posts = data;
  });

 });