I have a very simple webpage:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<title></title>
</head>
<body ng-app="nawApp">
<div ng-controller="StudentUse">
{{fullname}}
</div>
<script src="../Scripts/angular.js"></script>
<script src="../Scripts/angular-route.js"></script>
<script src="../Scripts/app.js"></script>
<script src="StudentUse.js"></script>
<script src="ServiceHttp.js"></script>
</body>
</html>
And I have my controller StundentUse.
/// <reference path="../scripts/app.ts" />
/// <reference path="ServiceHttp.ts" />
/// <reference path="../scripts/typescript/angular.d.ts" />
/// <reference path="Student.ts" />
module nawApp {
export interface IStundentScope extends ng.IScope {
returnData: string;
}
export class StudentUse {
static $inject = ['$scope', 'ServiceHttp'];
constructor($scope: IStundentScope, private serviceHttp: nawApp.ServiceHttp) {
$scope.returnData = serviceHttp.hello();
}
}
// StudentUse.$inject = ['$scope', 'ServiceHttp'];
nawApp.app.controller('StudentUse', StudentUse);
}
I have another file called ServiceHttp.ts, which is used by the upper code. The "ServiceHttp.ts" should be some kind of REST-Interface in the future, but up to now it simply returns a "Hello World" string:
/// <reference path="../scripts/app.ts" />
module nawApp {
export class ServiceHttp {
constructor() {}
hello(): string {
return "Hello world";
}
}
nawApp.app.controller('ServiceHttp', ServiceHttp);
}
If I launch my webpage, switch to the developer console, I get an error that saiys:
Error: [$injector:unpr] Unknown provider: serviceHttpProvider <- serviceHttp
I did't some investigation, but I cannot see the difference between examples that work and by solution with the error..... :-(
Any tips?
Thank You!
EDIT: This should be somehow the final code of the function in ServiceHttp.ts:
exampleFunction():string {
this.http.get(URL).success(function (data, status, headers, config) {
try {
return data;
}
catch (err) {
return err;
}
}).error(function (data, status, headers, config) {
return status;
});
return "";
}