system.import脚本没有在Angular中执行

时间:2017-07-18 06:32:29

标签: angular intellij-idea playframework-2.0

我在IntelliJ和Play Framework中创建了一个Angular2应用程序。以下代码给出了错误

<script>
                System.import('assets/app/main.js').catch(function(err){ console.error(err); });
        </script>

错误: Refused to execute inline script because it violates the following Content Security Policy directive: "default-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-ol8t6QICwIETK9dhrEwBShFCgKGwmDHZW/nmyLH+rYs='), or a nonce ('nonce-...') is required to enable inline execution. Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

1 个答案:

答案 0 :(得分:0)

html块中不允许使用内联JavaScript。最好的办法是将该代码移动到新的.js文件中,然后从块中调用该文件。

<script src="newscript.js"></script>

并在newscript.js

System.import('assets/app/main.js').catch(function(err){ console.error(err); });

结帐this reference,详细了解不允许使用内联脚本的原因。