2017-04-20 93 views
0

我打算在構造函數參數中傳遞一個值,這個接口類型是IDictation。但我得到這個錯誤:Typescript - 在構造函數中傳遞一個接口的數據類型錯誤

Uncaught Error: Can't resolve all parameters for DictationComponent: (?).

我假設打字機編譯器無法識別接口。雖然我輸入了它。

Dictation.Component.ts

import { Component, OnInit } from '@angular/core'; 
import {IDictation} from './IDictation'; 

@Component({ 
    selector: 'app-dictation', 
    templateUrl: './dictation.component.html', 
    styleUrls: ['./dictation.component.sass'], 

}) 
export class DictationComponent implements OnInit { 

    private usrLvl : IDictation;  
    constructor(usrLvl : IDictation) 
    {} 

    /** 

    code 

    **/ 
} 

回答

1

既然你不直接實例化的組件,而角呢,你只能使用構造函數的參數通過依賴注入的服務通過。

你想完成什麼?您可以使用私有變量和您的接口,而無需將其定義爲構造函數參數。

相關問題