我想使用我的API与AngularJS;我做了一个服务,我现在试图加载到一个控制器,但我看到一些错误。AngularJS服务注入器错误
Unknown provider: ApiServiceProvider <- ApiService <- ManageIntranetController
我正在使用TypeScript。
我的服务是这样的:
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);
})
};
}
}
}
我的控制器看起来像这样:
/// <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);' – devqon
另外,你不能注入'$ scope'到一个服务中,只有一个控制器和指令 – devqon
@devqon我没有那样做,但现在我仍然一直在接受相同的错误..哦,好的,我会改变这种情况。 – Peurr