-2
當使用角4和打字稿我已經定義了這個功能發箭不是一個函數
@Injectable() export class XService { display: (message?: string) => Promise<boolean>; } @Component({ templateUrl: './app/x/x.html', styleUrls: ['./app/x/x.component.css'] }) export class XEditComponent { constructor(private _xService: XService) { } deleteX(): void { let msg = "Do you really want to delete !"; this._xService.display(msg).then((responseOk) => { //..... }); } }
,但我總是得到一個類型錯誤「顯示」不是一個函數。
如果添加實際生成的代碼的一部分t他錯了。你如何試圖執行這個功能? –
你已經聲明'display'是一個函數,但是分配給它的是什麼?如果它沒有賦值,它將會是'undefined',如果你試圖把它作爲一個函數調用,那麼你所描述的錯誤將會受到影響。 – cartant