0
votes

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?

2
you should provide the service as a rpvoider in the component where it is used ..see there for example github.com/NativeScript/nativescript-sdk-examples-ng/blob/… - Nick Iliev

2 Answers

1
votes

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

0
votes

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