Dear Sir/Madam,

My program was working perfectly. Then I decided to forma base class as I 
could generalise. There is no error in the code and it compiles perfectly. 
However, when I run it, it gives this error.

ERROR TypeError: this.roleService.getData is not a function
    at AppRoleListComponent.push../src/app/role/role-list/role-list.
component.ts.AppRoleListComponent.ngOnInit (role-list.component.ts:41)
    at checkAndUpdateDirectiveInline (core.js:9250)
    at checkAndUpdateNodeInline (core.js:10514)
    at checkAndUpdateNode (core.js:10476)
    at debugCheckAndUpdateNode (core.js:11109)
    at debugCheckDirectivesFn (core.js:11069)
    at Object.eval [as updateDirectives] (AppRoleComponent.html:9)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:11061)
    at checkAndUpdateView (core.js:10458)
    at callViewAction (core.js:10699)

Please help resolve.

Regards,
Partha

BASE CLASS:

import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';

// import { Currency } from './currency.model';
import { ObjectColumnName } from '../ObjectColumnName';

// import { AppFooterComponent } from '../footer/footer.component';

@Injectable( { providedIn: 'root'} )
export abstract class ModuleService<T> {
protected dataList: T[] = [];
protected dataListUpdated = new Subject<T[]>();
protected dataFieldNames: ObjectColumnName[] = [];
protected baseURL = 'http://localhost:3000/api';
protected serviceRoute = '';
protected frontEndRouteToNavigate = '';

// private currencyFieldNames = { (id: 1, name:'CurrencyCode'),
// 'CurrencySymbol', 'CurrencyBaseName', 'FractionSymbol', 'FractionName'
// };

// constructor(private httpClient: HttpClient, private router: Router, 
public AppFooter: AppFooterComponent) {}
constructor(protected httpClient: HttpClient, private router: Router) {
// alert('in cons');
// this.setServiceRoute();
}

loggedInUser = 'partham';

getDataFieldNames() {
this.dataFieldNames = [];
this.getFieldNames();
// this.dataFieldNames.push({id: 1, name: 'CurrencyCode'});
// this.dataFieldNames.push({id: 2, name: 'CurrencySymbol'});
// this.dataFieldNames.push({id: 3, name: 'CurrencyBaseName'});
// this.dataFieldNames.push({id: 4, name: 'FractionSymbol'});
// this.dataFieldNames.push({id: 5, name: 'FractionName'});
return this.dataFieldNames;
}

protected abstract getFieldNames(): void;

protected abstract getServiceRoute(): string;

protected abstract setServiceRoute(): void;

// getData() {
// alert(this.baseURL + '/' + this.serviceRoute);
// this.httpClient.get<{message: string, values: T[], recordGoodCount: 
number}>(this.baseURL + '/' + this.serviceRoute)
// .subscribe((returnData) => {
// console.log(returnData.values.length);
// this.dataList = returnData.values;
// this.dataListUpdated.next([...this.dataList]);
// });
// }

abstract getOneData(codeToGet: string);

getDataUpdatedListener() {
return this.dataListUpdated.asObservable();
}

protected abstract getFrontEndRouteToNavigate(): string;

addNewData(newData: T) {
this.httpClient.post<{message: string, returnVal: number}>(this.baseURL + 
'/' + this.serviceRoute, newData)
.subscribe(responseData => {
console.log(responseData.message);
if (responseData.returnVal === 1) {
this.dataList.push(newData);
this.dataListUpdated.next([...this.dataList]);
this.router.navigate([this.frontEndRouteToNavigate]);
} else {
alert('Currency Add Failed');
}
});
}

updateData(codeToSearch: string, dataToUpdate: T) {
this.httpClient
.put<{message: string, returnVal: number}>(this.baseURL + '/' + this.
serviceRoute + '/' + codeToSearch, dataToUpdate)
.subscribe((returnValue) => {
if (returnValue.returnVal === 1) {
const updatedCurrencies = [...this.dataList];
const oldCurrencyIndex = this.getOldCurrencyIndex(updatedCurrencies, 
codeToSearch);
// updatedCurrencies.findIndex(c => c.currencyCode === 
this.codeToSearchForUpdate());
updatedCurrencies[oldCurrencyIndex] = dataToUpdate;
this.dataList = updatedCurrencies;
this.dataListUpdated.next([...this.dataList]);
this.router.navigate([this.getFrontEndRouteToNavigate()]);
} else {
alert('Currency Update Failed');
}
});
}

protected abstract getOldCurrencyIndex(dataToSearch: T[], codeToSearch: 
string): number;

deleteData(dataCode: string) {
// const dummy: T = {
// currencyCode: '',
// currencySymbol: '',
// currencyBaseName: '',
// fractionSymbol: '',
// fractionName: '',
// updateUser: this.loggedInUser
// };
const dummy = this.createDummy();

this.httpClient.patch<{message: string, returnVal: number}>(this.baseURL + 
'/' + this.serviceRoute + '/' + dataCode, dummy)
.subscribe((returnValue) => {
if (returnValue.returnVal === 1) {
const updatedData = this.getRecordsAfterDelete(dataCode); // 
this.dataList.filter(data => data.currencyCode !== dataCode);
this.dataList = updatedData;
this.dataListUpdated.next([...this.dataList]);
} else {
// alert('Currency Delete Failed');
}
});
}

protected abstract getRecordsAfterDelete(codeToSearch: string): T[];

protected abstract createDummy(): T;

// checkDuplicateCurrencyCode(currencyToCheck: T) {
// let bReturnValue = true;

// alert('Duplicate Check');
// if ( this.dataList.length > 0 ) {
// alert(this.dataList.findIndex(c => c.currencyCode === 
currencyToCheck.currencyCode));
// if (this.dataList.findIndex(c => c.currencyCode === 
currencyToCheck.currencyCode) > 0) {
// bReturnValue = false;
// }
// // this.currencyList.forEach(element => {
// // if ( element.currencyCode === currencyToCheck.currencyCode ) {
// // bReturnValue = false;
// // }
// // });
// }

// return bReturnValue;
// }

// checkDuplicateCurrencySymbol(currencyToCheck: Currency) {
// let bReturnValue = true;

// if (this.dataList.length > 0) {
// this.dataList.forEach(element => {
// if (element.currencySymbol === currencyToCheck.currencySymbol) {
// bReturnValue = false;
// }
// });
// }

// return bReturnValue;
// }

}



Inherited CLASS

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';

import { Role } from './role.model';
import { ModuleService } from '../general/module.services';

@Injectable( { providedIn: 'root' } )
export class RoleService extends ModuleService<Role> {
protected serviceRoute = 'role';
protected frontEndRouteToNavigate = '/role';

constructor(httpClient: HttpClient, router: Router) {
super(httpClient, router);
// this.setDataFieldNames();
// this.setFrontEndRouteToNavigate();
// this.createDummy();
}

protected getFieldNames(): void {
this.dataFieldNames.push({id: 1, name: 'RoleCode'});
this.dataFieldNames.push({id: 2, name: 'RoleName'});
}

protected getServiceRoute() {
return 'role';
}

protected setServiceRoute() {
this.serviceRoute = 'role';
}

getData() {
alert(this.baseURL + '/' + this.serviceRoute);
this.httpClient.get<{message: string, values: Role[], recordGoodCount: 
number}>(this.baseURL + '/' + 'role') // this.serviceRoute)
.subscribe((returnData) => {
console.log(returnData.values.length);
this.dataList = returnData.values;
this.dataListUpdated.next([...this.dataList]);
});
}

protected getFrontEndRouteToNavigate() {
return '/role';
}

getOneData(codeToGet: string) {
return this.httpClient.get<{message: string, data: Role}>(this.baseURL + '/' 
+ this.serviceRoute + '/' + codeToGet);
}

protected getOldCurrencyIndex(dataToSearch, codeToSearch) {
return dataToSearch.findIndex(c => c.roleCode === codeToSearch);
}

protected getRecordsAfterDelete(dataCode) {
return this.dataList.filter(data => data.roleCode !== dataCode);
}

protected createDummy() {
const dummy: Role = {
roleCode: '',
roleName: '',
updateUser: this.loggedInUser
};

return dummy;
}
}









-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to