I'm trying to make use of my API with AngularJS; I made a service which I'm now trying to load into a controller, but I'm seeing some errors.
Unknown provider: ApiServiceProvider <- ApiService <- ManageIntranetController
I'm using TypeScript.
My service looks like this:
module Services {
export class ApiService {
getIntranetItems: (action: string) => any;
constructor($scope, $http: ng.IHttpService) {
this.getIntranetItems = (action: string) => {
return $http({
method: "GET",
url: "https://localhost:44326/api/intranet/" + action,
headers: { 'Content-Type': 'application/json' }
}).success(function (data) {
$scope.intranetItems = data;
}).error(function (msg) {
alert("ERROR: " + msg);
})
};
}
}
}
And my controller looks like this:
/// <reference path="../services/apiservice.ts" />
module Controllers {
export interface IManageIntranetController extends ng.IScope {
}
export class ManageIntranetController {
constructor($scope: IManageIntranetController, ApiService: Services.ApiService) {
console.log(ApiService.getIntranetItems("get"));
}
}
}
angular.module("myApp", []).service("ApiService", Services.ApiService);$scopeinto a service, that one is only for controllers and directives