2016-04-06 4 views
0

ファイルをアップロードするには、ng-adminでカスタムフィールドを定義します。私は文書hereを使用します。カスタムタイプ:フィールドクラスがオブジェクトではなく関数として注入されます

私はリポジトリadmin-configを含んでいます。

次のように私のCustomeFileFieldを定義します。

import Field from "./admin-config/lib/Field/Field.js"; 

class CustomFileField extends Field { 
    constructor(name) { 
     super(name); 
     this._type = 'customfile'; 
     this._id = undefined; 
     this._entity_field = undefined; 
     this._upload_information = {}; 
} 

uploadInformation(baseUrl) { 
    if(!argument.length) return this._upload_information; 
    if(typeof this._id === 'undefined') { 
     throw new Error('You must provide a valid id for the entity'); 
    } 
    this._upload_information = { 
       'url': baseUrl + 'fr/media/upload?ref_id='+ this._id +'&ref=OpnRecipeBundle\\Entity\\Recipe', 
       'apifilename': 'files' 
    }; 
    return this; 
} 

// value of the entity id 
id(value) { 
    if(!argument.length) return this._id; 
    this._id = value; 
    return this; 
} 
//name of the field in the entity id 
entityField(value) { 
    if(!argument.length) return this._entity_field; 
    this._entity_field = value; 
    return this; 
    } 
} 
export default CustomFileField; 

そして、私はドキュメントに対応するビューのaccordindを定義します。

私は現在の両方を登録します。

nga.registerFieldType('customfile', require('./CustomFileField.js')); 
fvp.registerFieldView('customfile', require('./CustomFileFieldView.js')); 

は、その後、私はと私たての新しい定義タイプを呼び出す:

nga.field('itsname','customfile'); 

それでも私はきちんとすべてをtranspilingした後、現在のエラーを持っている:

Error: [$injector:modulerr] Failed to instantiate module opnAdmin due to: this._fieldTypes[t] is not a constructor

物事を慎重にロギングすると、フィールドタイプタイプcollecti onにはネイティブのng-adminタイプの各タイプに1つずつのエントリがありますが、それは関数ですが、新しい定義型( 'customfile')の場合はオブジェクトなので、new演算子を呼び出すとエラーが発生します。その人のための任意のソリューションですか?

+0

require( 'CustomField.js')を使用するとオブジェクトが返されますが、代わりに 'CustomField.js'からimport CustomFieldを使用すると関数を返して動作します。 – user2626210

答えて

0

require( 'CustomField.js')を使用するとオブジェクトが返されますが、代わりに 'CustomField.js'からimport CustomFieldを使用すると関数を返して動作します。

関連する問題