gpt4 book ai didi

javascript - 将组件 View 附加到主体

转载 作者:太空狗 更新时间:2023-10-29 18:00:15 28 4
gpt4 key购买 nike

Angular 7/ngx-bootstrap 4.0.1

依赖:

"bootstrap": "3.3.7",
"bootstrap-colorpicker": "2.5.1",
"bootstrap-duallistbox": "3.0.6",
"bootstrap-markdown": "2.10.0",
"bootstrap-progressbar": "0.9.0",
"bootstrap-slider": "9.8.0",
"bootstrap-tagsinput": "0.7.1",
"bootstrap-timepicker": "0.5.2",

在 Angular 7 中,我有一个组件。它只是一个按钮,当您单击它时,它会显示一个模式。

如果我从像 div 这样的元素调用它,它就可以工作。

但是当我从下拉菜单中调用它时,模式不会出现。

这是我的代码:

正常调用:模态可见:

<shared-article-copy (ArticleEM)="addArticle($event, 'articleCopie')" [agentId]="this.samplesBill.recipient.agent_Id"
*ngIf="this.samplesBill && this.samplesBill.recipient"></shared-article-copy>

从下拉菜单调用:模式不可见:

<div class="btn-group">
<button type="button" class="btn btn-primary">Apple</button>
<button type="button" class="btn btn-primary">Test 1</button>
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
Test2 <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<li> <shared-article-copy (ArticleEM)="addArticle($event, 'articleCopie')" [agentId]="this.samplesBill.recipient.agent_Id"
*ngIf="this.samplesBill && this.samplesBill.recipient"></shared-article-copy></li>
</ul>
</div>
</div>

我认为,我的组件的 View 绑定(bind)到 li 元素而不是主体。

这是我的组件 View shared-article-copy 的部分代码:

<button type="button" class="btn btn-labeled btn-primary" (click)="loadModalArticleImport()" ng-dblclick="return false;">
<span class="btn-label">
<i class="fa fa-plus"></i>
</span>{{ textTitle }}
</button>

<div bsModal #calculatorModal="bs-modal" class="modal fade" tabindex="0" role="dialog" aria-labelledby="myLargeModalLabel"
aria-hidden="true" style="background-color: white" [hidden]="!articleCalculator" (onHidden)="closeCalculatorModal()"
>
<div class="modal-dialog modal-lg" style="background-color: white">
<div class="modal-content">
<div class="modal-header" *ngIf="articleCalculator">
Modal Header
</div>
<div class="modal-body">
modal body !
</div>
</div>
</div>
</div>

我无法复制组件的所有代码,因为它们不相关。

这是一部分:

export class SharedArticleCopyComponent implements OnInit {

@Input() buttonClass: string;
@Input() agent: Agent; // pour avoir un client par défaut
@Input() agentId: string; // Quand on a pas lagent mais que son ID people
@Input() textTitle: string = 'Copier un article existant';
@Input() calculatorTitle: string = 'Détails de l\'article: ';
@Input() AgentReadonly: boolean = false;

@Output() public ArticleEM: EventEmitter<Article> = new EventEmitter<Article>();

@ViewChild('copyArticleModal') public lgModal: ModalDirective;
@ViewChild('calculatorModal') public lgCalculatorModal;

constructor(private httpClient: HttpClient, private articlesService: ArticlesService, public agentsClientsService: AgentsClientsService, public peopleService: PeopleService,
private sessionService: SessionService, private _route: ActivatedRoute,
private notificationLGIService: NotificationLGIService, private datePipe: DatePipe, private domService: DomService) {

}

即使我从下拉菜单中调用组件,我怎样才能使模态可见?

编辑以添加 loadModalArticleImport 的内容:

//lgModal: @ViewChild('copyArticleModal') public lgModal: ModalDirective;
loadModalArticleImport() {
this.lgModal.show();
}

最佳答案

您看不到模态框,因为它在打开时是隐藏下拉菜单的子菜单。

当您将组件放入下拉列表中时,您最终会得到以下 DOM 结构。

drop-down menu(position:absolute) > shared-article-copy > modal(position:fixed)

当您单击按钮打开模式时,模式会打开,但下拉菜单也会关闭,显示设置为 none

drop-down menu(display:none) > shared-article-copy > modal(position:fixed)

因此您看不到下拉菜单及其任何子项(包括您的模式)。

解决方案:

  1. 不要将模式放在下拉列表中(推荐)。
  2. 为包含模式 (demo on stackblitz) 的下拉菜单修补 bootstrap CSS。

包含模式的引导下拉菜单的 CSS:

.dropdown-menu.contains-modal {
position: unset;
display: inline-block;
height: 0;
width: 0;
min-width: unset;
overflow: hidden;
border: 0;
padding: 0;
}
.open>.dropdown-menu.contains-modal {
position: absolute;
height: unset;
width: unset;
min-width: 160px;
padding: 5px 0;
border: 1px solid rgba(0,0,0,.15);
overflow: unset;
}

并使用

<ul class="dropdown-menu contains-modal">...

代替

<ul class="dropdown-menu">...

关于javascript - 将组件 View 附加到主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56306101/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com