我遇到了使用angular2和typescript加載nativescript應用程序的問題。我試圖解決很長時間。我所擁有的是:nativescript和angular2 - 無提供程序錯誤
list.service.ts
import { ItemListApi } from '../sdk/services/custom/ItemList';
import { ItemList } from '../sdk/models/ItemList';
@Injectable()
export class ListService {
items: Observable<Array<Item>>;
public grocery: Grocery = new Grocery('', '');
private listModel: ItemList = new ItemList();
constructor(private itemListApi: ItemListApi,
private authModelApi: AuthModelApi,
private loginCredentials: LoginCredentials) {
}
addItems(list: ItemList) {
let uid;
uid = this.loginCredentials.getUserId();
return this.itemListApi.create({
"name": list.name,
"userid": uid
});
};
}
module.ts
@NgModule({
imports: [
CommonModule,
FormsModule,
RouterModule
],
declarations: [
LoginComponent,
ListComponent
],
providers: [
LoginService,
ListService,
LoginCredentials,
HeroActions,
HeroService
],
exports: [
LoginComponent,
ListComponent
]
})
我收到錯誤消息說 「不提供商ItemListApi」 的所有時間... 其實ItemListApi來自我的loopback nativescript sdk。 有人可以幫我發現我的代碼的小問題?
你應該提供的服務爲一個rpvoider在它使用的組件。例如https://github.com/NativeScript/nativescript-sdk-examples-ng/blob/master/app/http/http-get/http-get.component .ts –