使用.indexOf获取TypeScript作用域错误

时间:2017-03-28 07:28:54

标签: angular typescript

如何将其转换为正确的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) {
        ...

因为我收到范围错误:

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

1 个答案:

答案 0 :(得分:1)

我认为你的意思是

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