2017-09-23 3 views
0

저는 요소를 만들고 가져오고 데이터로 속성을 설정합니다. 이전에 요소를 가져 오거나 만들지 않은 경우에만 코드가 실행되기를 원합니다. 함수가 호출 될 때 나는 다음과 같은 오류가 발생합니다 : 무슨 일이 일어나고 무엇Polymer 2.0 createElement를 작성한 다음 Polymer.importHref로 가져오고 setAttribute를 사용하여 데이터를 전달합니다.

this._dialogPopUp.open is not a function 

는 요소가 생성되고 가져 오기 전에 this._dialogPopUp.open();가 실행된다는 점이다. 두 번째로 버튼을 누르면 팝업이 생성되고 가져 오기되기 때문에 작동합니다. 요소를 생성하고 가져올 때까지 기다렸다가 실행을 계속할 수있게하려면 어떻게해야합니까?

현재 나는이 구현이 있습니다

_loadDialogPopUp(e) { 
    let me = this; 
    if(!me._dialogPopUp){ 
    me._dialogPopUp = document.createElement('su-dialog'); 
    Polymer.importHref(this.resolveUrl('su-dialog.html'), (e) => { 
     this.root.appendChild(this._dialogPopUp); 
    }); 
    } 
    customElements.whenDefined('su-dialog').then(() => { 
    me._dialogPopUp.open(); 
    me._dialogPopUp.setAttribute('uid', this.user.uid); 
    }) 
} 

답변

0

당신은 당신이 기능의 사용하기 전에 요소가 실제로 "업그레이드"되어 있는지 확인해야합니다. 운 좋게도 그 표준 생각. 자세한 내용은 참조하십시오 https://developers.google.com/web/fundamentals/architecture/building-components/customelements

+0

customElements.whenDefined('su-dialog').then(() => { this._dialogPopUp.open(); this._dialogPopUp.setAttribute('uid', this.user.uid); }); 

, 감사 올바른 방향으로 보인다. 'customElements.whenDefined'를 구현하는 코드를 업데이트했습니다. 새로 생성 된 요소에 대한 참조는 어떻게 얻을 수 있습니까? –