Reputation: 416
As shown I'm attempting to use a controller to retrieve a JSON file,But the error
"Failed to instantiate module getJson due to: Error: [$injector:nomod] http://errors.angularjs.org/1.2.23/$injector/nomod?p0=get..."
Keep popping up. I have already referenced the angular dependency ngRoute here.
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>
Controller
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;
});
});
Upvotes: 1
Views: 107
Reputation: 5487
You have added the angular-route file but you have not added it as a dependency in your module. Please use
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;
});
});
Upvotes: 0