I am new to Angular JS and have getting below error when I have tried to inject $http service in the project. Please see the code file below.
As you can see I have created a <ng-app="myapp">
and created a controller for the same. As described in the tutorial I have registered the controller in the View.js and tried to load 'data.json' file data. However, during running the program I am getting error as $http is not defined.
View.html
<!DOCTYPE html>
<html lang="en">
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
<script src="js/View.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="Object">
<span ng-bind="o.rollNo"></span>
<span ng-bind="o.firstName"></span>
<span ng-bind="o.middleName"></span>
<span ng-bind="o.lastName"></span>
<span ng-bind="o.className"></span>
<span ng-bind="o.schoolName"></span>
</div>
</body>
</html>
View.js
var app=angular.module("myapp", []);
app.controller('Object',function($scope,$http) {
$http.get("data.json")
.success( function(response) {
$scope.o= response;
});
});
data.json:
[
{
"rollNo" : "1",
"firstName" : "ABC",
"middleName" : "DEF"
"lastName" : "HIJ"
"className" : "First"
"schoolName" : "CRB"
}
]
` tag.
– Mike Eason Jan 25 '16 at 14:34` tag?
– serv-inc Jan 25 '16 at 14:56