简体   繁体   中英

nativescript and angular2 - no Provider Error

I've got problem with loading nativescript app using angular2 and typescript. I'm trying to solve for long time. What i have is:

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
]
})

All the time I'm getting error message saying "No provider for ItemListApi" ... actually ItemListApi is from my loopback nativescript sdk. can someone help me spot that small issue with my code?

Add ItemListApi into your app.module.ts 's provider list:

providers: [
LoginService,
ListService,
LoginCredentials,
HeroActions,
HeroService,
ItemListApi
],

In reply to what Nick said, he cant add it as a provider in the ts file he's in as he is using @Injectable not @Component

As mentioned in the comments; you need to update your imports in the module.ts file.

Add:

import { SDKBrowserModule } from './shared/sdk/index';

with the other imports in your module.ts, then also:

SDKBrowserModule.forRoot()

in your imports array in module.ts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM