1
我正在使用Angular2與Typescript。Angular2類名碰撞
我創建了一個名爲Input
的類,並試圖在其中一個使用Input
註釋的組件中使用它。現在,當我試圖創建我Input
類的實例,我得到了一個不正確的實例InputMetadata
這顯然是由於與Input
進口衝突「@角/核心」:
import { Component, Input, OnInit } from '@angular/core';
import { Input } from '../controls/input';
@Component({
moduleId: module.id,
selector: 'dynamic-form',
templateUrl: 'dynamic-form.component.html',
directives: [DynamicFormInputComponent, REACTIVE_FORM_DIRECTIVES],
})
export class DynamicFormComponent implements OnInit {
ngOnInit() {
let control = new Input({});
console.log(control);
}
}
有沒有一種辦法本地別名類例如以便我的Input
將作爲FormInput導入。如果不是,則無需重命名我的Input
類,該問題的合理解決方案是什麼。
'import {... as ....}'........... –
我真的會避免使用'reserved names'作爲你自己類的名字。但@ peeskillet的評論應該可以幫到你 –