Louis
Louis

Reputation: 2608

Getting a TypeScript scoping error with .indexOf

How can I convert this to proper TypeScript (Angular2) ?

import { UtilsService } from '../providers/utils-service';

@Injectable()
export class ImagesService {

    constructor(
          private connectionStatus: ConnectionStatus
        , private UrlExists: UrlExists
        , private storageService: LocalStorageService
        , private UtilsService: UtilsService
    ) {
    }

    usualTreatment(prodata, gotANewDB) {
        if (str.indexOf(suffix, this.length - suffix.length) === -1) {
        ...

because I get a scope error :

Typescript Error
Property 'length' does not exist on type 'ImagesService'.
src/providers/images-service.ts
for (var str in imagesUrls) {
    if (str.indexOf(suffix, this.length

Upvotes: 0

Views: 108

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657376

I assume you mean

if (str.indexOf(suffix, str.length - suffix.length) === -1) {
                        ^^^

Upvotes: 1

Related Questions