我想使用我的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