0

I am new in both angular2 and .net core I followed this tutorial and learned pretty solution to work with angular (and .netcore). I just have a problem!

When I create a service like this:

import { Injectable } from '@angular/core'
import { Http } from '@angular/http'
import 'rxjs/RX'
import { AccountSummary } from './account-summary.type'
import { AccountDetail } from './account-detail.type'
import { AccountType } from './account-type.enum'

@Injectable()

export class AccountService
{
    constructor(private http : Http)
    {
     }
getAccountSummeries()
{
    debugger
    return this.http.get('api/Bank/GetAccountSummeries')
        .map(response => response.json() as AccountSummary[])
        .toPromise();
}
}

and import it in app.module.share.ts file:

   .
   .

import { AccountService } from './components/shared/account.service' //Here<<


export const sharedConfig: NgModule = {
    bootstrap: [AppComponent],

    //Namespace Off Components:
    declarations: [
        AppComponent,
        NavMenuComponent,
        CounterComponent,
        FetchDataComponent,
        HomeComponent,
        AccountlistComponent,
        AccountSummaryComponent,
        ExampleComponent,
        FormatAccountNumberPipe,

        HeaderComponent
    ],
    imports: [
        RouterModule.forRoot([
         //paths...
        ])
    ],
    providers: [AccountService] //Here<<<<<<<<<<<<<<<<<<<<<

};

iv got this error when i ran the application:

Exception: Call to Node module failed with error: Error: Uncaught (in promise): Error: No provider for AccountService! Error: No provider for AccountService! at Error (native)

I use my service like this:

import { Component } from '@angular/core';
import { AccountSummary } from '../../shared/account-summary.type'
import { AccountType } from '../../shared/account-type.enum'
import { AccountService } from '../../shared/account.service'

@Component({
    selector: 'account-list',
    templateUrl: './account-list.component.html'
})
export class AccountlistComponent {

    cashAccounts: AccountSummary[];
    creditAccounts: AccountSummary[];
    constructor(private accountService: AccountService) { 
    }

    ngOninit() {
        this.accountService.getAccountSummeries().then(accounts => { 
        this.cashAccounts = accounts })
    }
}
2
  • 1
    Could you also show you app.module file. Commented Jul 25, 2017 at 14:12
  • @MattSugden i actually made confuse ...my proj is angular SPA template with .net core and i have 3 app.module named:{app.module.client , app.module.server,app.module.shared}...the problem solved when i add this provide in app.module.server!!!!! Commented Jul 26, 2017 at 5:13

1 Answer 1

2

According to the exception, you didn't add in module. Add AccountService in your app.module.ts file

providers: [AccountService] 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks ....i actually made confuse ...my proj is angular SPA template with .net core and i have 3 app.module named:{app.module.client , app.module.server,app.module.shared}...the problem solved when i add this provide in app.module.server!!!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.