[英]nativescript and angular2 - no Provider Error
我在使用angular2和Typescript加載nativescript應用程序時遇到問題。 我想解決很長時間。 我所擁有的是:
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來自我的環回本機sdk。 有人可以幫助我發現我的代碼中的那個小問題嗎?
將ItemListApi
添加到app.module.ts
的提供程序列表中:
providers: [
LoginService,
ListService,
LoginCredentials,
HeroActions,
HeroService,
ItemListApi
],
為了回應Nick所說的,他無法在使用@Injectable
而不是@Component
將其添加為ts文件中的提供程序。
如評論中所述; 您需要在module.ts文件中更新導入。
加:
import { SDKBrowserModule } from './shared/sdk/index';
以及module.ts中的其他導入,然后:
SDKBrowserModule.forRoot()
在module.ts中的導入數組中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.