2017-03-28 85 views
0

你能幫我把它轉換成正確的打字稿(angular2)嗎?typescript範圍錯誤與.indexOf

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

你有ImagesService類 –

+2

this.length屬性,我們需要更多的背景下,什麼是包裝if語句,方法,函數,箭頭函數?請提供更多的代碼,如果需要的話,你的整個班級。 – n00dl3

+1

請發送'images-service.ts'代碼 –

回答

1

我假定你的意思

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

是的...... pfff簡單;) – Louis