2017-02-19 1 views
1

이 코드가 Chrome에서는 작동하지만 Safari에서는 작동하지 않는 이유는 무엇입니까? Error : ReferenceError : 변수를 찾을 수 없습니다. PolymerSimple Polymer 구성 요소가 Safari 10에서 작동하지 않습니다.

Mac OSX 10.11.6.

코드 : 크롬 <link rel="import">에 동 기적으로 처리되기 때문에 (기본적으로 구현되지 때문에)

<!DOCTYPE html> 
<html> 
<head> 
    <title>Test</title> 
    <script src="/node_modules/webcomponents.js/webcomponents-lite.min.js"></script> 
    <link rel="import" href="/node_modules/Polymer/polymer.html"> 
</head> 
<body> 
    <dom-module id="my-test"> 
    <template> 
     Hello ! 
    </template> 
    </dom-module> 

    <script> 
    Polymer({ 
     is: 'my-test' 
    }); 
    </script> 

    <my-test> 
    </my-test> 
</body> 
</html> 

답변

3

그것은 Safari에서 처음 동안 인식하지,입니다. 따라서 Polymer()은 구문 분석 될 때 정의되지 않습니다.

Polymer()를 호출하기 전에 HTMLImportsLoaded 이벤트가 발생할 때까지 기다려야합니다. Polymer documentation에 설명 된대로

<script> 
    document.addEventListener("HTMLImportsLoaded", function() { 
     Polymer({ 
      is: 'my-test' 
     }); 
    }) 
</script> 

당신은 대신 HTMLImports.whenReady()를 사용할 수 있습니다.

<script> 
    HTMLImports.whenReady(function() { 
     Polymer({ 
      is: 'my-test' 
     }); 
    }) 
</script> 
+0

도움이된다면 upvote 할 수 있습니다. :) – Supersharp

관련 문제