Javascript 将零部件视图附加到主体

Javascript 将零部件视图附加到主体,javascript,html,angular,angular7,Javascript,Html,Angular,Angular7,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

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",
<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>
在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>
我无法复制组件的所有代码,因为它不相关

以下是一部分:

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) {

  }

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

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

drop-down menu(position:absolute) > shared-article-copy > modal(position:fixed)
当您单击按钮打开模态时,模态打开,但下拉列表也关闭,显示设置为
none

drop-down menu(display:none) > shared-article-copy > modal(position:fixed)
因此,您看不到下拉列表及其任何子项(包括模态)

解决方案:

  • 不要将模态放在下拉列表中(推荐)
  • 修补包含模态()的下拉列表的引导CSS
  • 包含模式的引导下拉列表的CSS:

    .dropdown-menu.contains-modal{
    位置:未设置;
    显示:内联块;
    身高:0;
    宽度:0;
    最小宽度:未设置;
    溢出:隐藏;
    边界:0;
    填充:0;
    }
    .open>.dropdown-menu.contains-modal{
    位置:绝对位置;
    高度:未设置;
    宽度:未设置;
    最小宽度:160px;
    填充:5px0;
    边框:1px实心rgba(0,0,0,15);
    溢出:未设置;
    }
    
    和使用

    <ul class="dropdown-menu contains-modal">...
    
      。。。
    而不是

    <ul class="dropdown-menu">...
    
      。。。
    您可以使用模板中的
    操作符缩短访问属性时的安全检查。比如,
    *ngIf=“this.samplesBill&&this.samplesBill.recipient”
    可以缩短为仅
    *ngIf=“this.samplesBill?.recipient”
    请更新您的问题,告诉我们您正在使用哪个Angular引导库。@cgTag我已经更新了我的问题。希望这是你需要的。@Munimuna我已经编辑了我的问题。你能提供stackblitz的最低复制版本吗
    <ul class="dropdown-menu">...