【发布时间】:2020-05-19 07:04:31
【问题描述】:
尝试从不同的组件调用创建标签模式。
我正在使用的组件称为宠物,位于: app/main/ClientPatientManagement/Pets
尝试访问 show() 方法: app/main/tags/tags/create-or-edit-tag-modal.component'
这是我 Pets.Component 中的代码:
import { CreateOrEditTagModalComponent } from '@app/main/tags/tags/create-or-edit-tag-modal.component';
@Component({
templateUrl: './pets.component.html',
encapsulation: ViewEncapsulation.None,
animations: [appModuleAnimation()]
})
export class PetsComponent extends AppComponentBase {
@ViewChild('createOrEditTagModal', { static: true }) createOrEditTagModal: CreateOrEditTagModalComponent;
这里有一些其他代码,包括 ngOnInit 等,但我想在按下按钮时调用以下函数:
createTag(): void {
this.createOrEditTagModal.show();
}
我的问题是我不断收到错误消息说我的 this.createOrEditTagModal 未定义。
我还在我的 main.module.ts 中导入了这个组件并将其添加到我的声明中。
谁能帮我解释为什么这一直是未定义的?
编辑: 为了完整起见,我添加了一些来自 create-or-edit-tag-modal-component 的代码
@Component({
selector: 'createOrEditTagModal',
templateUrl: './create-or-edit-tag-modal.component.html'
})
export class CreateOrEditTagModalComponent extends AppComponentBase {
@ViewChild('createOrEditModal', { static: true }) modal: ModalDirective;
@Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
constructor(
injector: Injector,
private _tagsServiceProxy: TagsServiceProxy
) {
super(injector);
}
show():void{
console.info("Called tag component successfully!"); //for testing
}
【问题讨论】:
-
create-or-edit-tag-modal 中是否有类?您是否尝试过添加@Injectable?
-
嗨 Tsakiroglou,create-or-edit-tag-modal 中有一个类,我更新了我的问题以包含其中的摘录。你能发现那里有什么问题吗?
-
哦,我明白了,谢谢,恐怕我什么也没看到。我会深入研究。