ng bootstrap + angular 4:动态 html 模态内容加载
ng boostrap + angular4: dynamical html modal content loading
我有以下架构:
.
├── companies.component.ts
├── companies.html
├── companies.service.ts
└── components
└── modal
├── modal.component.html
└── modal.component.ts
我的模态组件如下所示:
@Component({
selector: 'service-modal',
templateUrl: './modal.component.html'
})
export class ModalComponent implements OnInit {
public modalHeader: string;
public modalContent: string;
constructor(private activeModal: NgbActiveModal) {
}
public ngOnInit() {
}
public closeModal() {
this.activeModal.close();
}
}
我从我的 companies.component.ts
中像这样使用它:
const activeModal = this.modalService.open(ModalComponent, { size: 'lg' });
activeModal.componentInstance.modalHeader = 'Create company';
activeModal.componentInstance.modalContent = 'company form';
我想使用模式组件创建公司或用户实体。将 html 表单绑定到 modalContent 是一个好习惯吗?还有其他方法吗?我应该创建两个不同的模态组件(一个给用户,一个给公司)吗?
首先,您可能会在其他地方重复使用您的模式。所以你应该把这个组件放在 'shared' 文件夹中。
那么你有多种解法:
- 含 ng 内容。您创建模态组件或使用 bootstrap 的。
<my-modal>
<my-comp-to-create-companies>
</my-comp-to-create-companies>
</my-modal>
<my-modal>
<my-comp-to-edit-companies></my-comp-to-edit-companies>
</my-modal>
您可以合并 edit/create 个组件,因为表单可能具有相同的属性。
我有以下架构:
.
├── companies.component.ts
├── companies.html
├── companies.service.ts
└── components
└── modal
├── modal.component.html
└── modal.component.ts
我的模态组件如下所示:
@Component({
selector: 'service-modal',
templateUrl: './modal.component.html'
})
export class ModalComponent implements OnInit {
public modalHeader: string;
public modalContent: string;
constructor(private activeModal: NgbActiveModal) {
}
public ngOnInit() {
}
public closeModal() {
this.activeModal.close();
}
}
我从我的 companies.component.ts
中像这样使用它:
const activeModal = this.modalService.open(ModalComponent, { size: 'lg' });
activeModal.componentInstance.modalHeader = 'Create company';
activeModal.componentInstance.modalContent = 'company form';
我想使用模式组件创建公司或用户实体。将 html 表单绑定到 modalContent 是一个好习惯吗?还有其他方法吗?我应该创建两个不同的模态组件(一个给用户,一个给公司)吗?
首先,您可能会在其他地方重复使用您的模式。所以你应该把这个组件放在 'shared' 文件夹中。
那么你有多种解法:
- 含 ng 内容。您创建模态组件或使用 bootstrap 的。
<my-modal> <my-comp-to-create-companies> </my-comp-to-create-companies> </my-modal> <my-modal> <my-comp-to-edit-companies></my-comp-to-edit-companies> </my-modal>
您可以合并 edit/create 个组件,因为表单可能具有相同的属性。