을 만드는 방법에는 모달 팝업과 호환되는 각 4

고 싶을 만들 수 있는 팝업 창에는 것을 로드하는 특정 각 4 구성 요소의 광산 경우 라디오 버튼을 선택합니다.

그것은 나와 있는 방법에 대한 답변 이[question](https://stackoverflow.com/questions/35400811/how-to-use-codes-to-open-a-modal-in-angular-2 용)호환을 가진 모난 접 2.

나는 어디서부터 시작 해야할지고 어떤 도움을 주셔서 감사합니다!

질문에 대한 의견 (4)

허용되는 대답을 추가 큰 종속성을 swat 있습니다. 모달(및 모달리스)대화 상자를 주로 결과의 CSS 클래스 또는 두 가지입니다. 이"이름 바꾸기..."예를 들어:

1)부모와 자식-modal 로 경우 자식이 아니었't 달에서 모든지만,인라인 형식으로*ngIf 첨부됩니다.

부모는 HTML 사용하는<my-modal>아동:

<div>
    A div for {{name}}.
    Rename

</div>

부모 클래스입니다. 는@구성 요소장식 생략됩니다. (는이름속한 부모 클래스와 존재하는 경우에도 우리는't 양식을 변경합니다.)

export class AppComponent {
    name = "old name";

    showIt = false;
    showModal() {
        this.showIt = true;
    }
    closeModal(newName: string) {
        this.showIt = false;
        if (newName) this.name = newName;
    }

}

아이 될-모달 구성 요소입니다. @구성 요소장식하고 수입 다시 생략됩니다.

export class MyModalComponent {
    @Input() oldname = "";
    @Output() close = new EventEmitter();
    newname = "";

    ngOnInit() {
        // copy all inputs to avoid polluting them
        this.newname = this.oldname; 
    }

    ok() {
        this.close.emit(this.newname);
    }

    cancel() {
        this.close.emit(null);
    }
}

아 HTML 기 전에는 모달-izing 니다.

<div>
    Rename {{oldname}}
    <input type="text" (change)="newname = $event.target.value;" />
    OK
    Cancel
</div>

2)여기서는's CSS 에 대한 아이지만,그것은 배치할 수 있습에서 글로벌 스타일 시트를 다시 사용하기 위해내합니다. It's 하나의 클래스 라는modal과 의도에 대한<div>요소입니다.

.modal {
    /* detach from rest of the document */
    position: fixed;

    /* center */
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    /* ensure in front of rest of page -- increase as needed */
    z-index: 1001;

    /* visual illusion of being in front -- alter to taste */
    box-shadow: rgba(0,0,0,0.4) 10px 10px 4px;

    /* visual illusion of being a solid object -- alter to taste */
    background-color: lightblue;
    border: 5px solid darkblue;

    /* visual preference of don't crowd the contents -- alter to taste */
    padding: 10px;
}

하지만modalCSS 클래스 승't 방지와 상호 작용하는 페이지합니다. (그래서 기술적으로 만듭 모니다.) 그래서 우리는오버레이아래에는 모달을 흡수하고 무시하는 마우스를 활동입니다.는 또한 용도에 대한<div>요소입니다.

.overlay {
    /* detach from document */
    position: fixed;

    /* ensure in front of rest of page except modal */
    z-index: 1000;

    /* fill screen to catch mice */
    top: 0;
    left: 0;
    width: 9999px;
    height: 9999px;

    /* dim screen 20% -- alter to taste */
    opacity: 0.2;
    background-color: black;
}

3)사용하여modal그리고`오버레이에 아이는 HTML.

<div class="modal">
    Rename {{oldname}}
    <input type="text" (change)="newname = $event.target.value;" />
    OK
    Cancel
</div>
<div class="overlay"></div>

고는's 니다. 기본적으로 2CSS 클래스고 만들 수 있는 모든 구성 요소는 모달입니다. 사실 당신을 보여줄 수 있는 구성 요소에 온라인으로 모달에는 실행 시간에 의해 변질의 존재 CSS 클래스ngClass또는[클래스입니다.모달]="showAsModalBoolean"입니다.

을 변경할 수 있습니다 그래서 이 아이는 컨트롤 보이기/숨기기 논리입니다. 이동*ngIf,showIt,and show()함수로 아이입니다. 에서 부모를 추가@ViewChild(MyModalComponent)renameModal:MyModalComponent;,그리고 부모할 수 있는 명령적으로 호출이다.renameModal.쇼(다.name);그리고 다시 와이어 초기화하고 포함하는 div 으로 필요합니다.

아동 모달 반환할 수 있는 정보는 부모에게's 능과 같은 위 또는 아's show()메서드에 대신 받을 콜백 또는 반환 약속에 따라,맛이 있습니다.

두 가지 일을 알고:

이다.renameModal.쇼(..);지't 작업하는 경우가 있's anngIf 에<my-modal>기 때문에 그't 존재를 노출하는 함수로 시작합니다. ngIf 제거하는 전체 구성 요소,쇼()함수,그래서 사용[숨겨진]"대신에"필요하신 경우에는 이를 위해 몇 가지 이유입니다.

조동-on-조동이 있는 z-index 문제 때문에 그들은 모두가 공유하는 동 z-index. 이는 해결될 수 있으로[스타일입니다.z-index]="calculatedValue"또는 이와 유사한.

해설 (4)
해결책

체크인각 물질의 대화,여기에Plunker

import {Component} from '@angular/core';
import {MdDialog, MdDialogRef} from '@angular/material';

@Component({
  selector: 'dialog-result-example',
  templateUrl: './dialog-result-example.html',
})
export class DialogResultExample {
  selectedOption: string;

  constructor(public dialog: MdDialog) {}

  openDialog() {
    let dialogRef = this.dialog.open(DialogResultExampleDialog);
    dialogRef.afterClosed().subscribe(result => {
      this.selectedOption = result;
    });
  }
}

@Component({
  selector: 'dialog-result-example-dialog',
  templateUrl: './dialog-result-example-dialog.html',
})
export class DialogResultExampleDialog {
  constructor(public dialogRef: MdDialogRef) {}
}
해설 (9)