【问题标题】:Integrating Angular 2 with Symfony 3将 Angular 2 与 Symfony 3 集成
【发布时间】:2016-03-17 03:18:07
【问题描述】:

我正在尝试将 Angular 2 与 Symfony 3 集成。我使用 npm 安装节点模块,但是我无法从我的视图 base.html.twig 链接它们。事实上,我添加的每个脚本都不起作用(甚至在页面的源代码中也不行)。

以下脚本是必需的,如何添加它们?

<!-- IE required polyfills, in this exact order -->
<script src="../../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../../node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="../../node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>

<script src="../../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../../node_modules/systemjs/dist/system.src.js"></script>
<script src="../../node_modules/rxjs/bundles/Rx.js"></script>
<script src="../../node_modules/angular2/bundles/angular2.dev.js"></script>
<script>
      System.config({
        packages: {
          app: {
            format: 'register',
            defaultExtension: 'js'
          }
        }
      });
      System.import('../components/main')
            .then(null, console.error.bind(console));
</script>

【问题讨论】:

    标签: javascript angular symfony


    【解决方案1】:

    在 symfony 中,网站的根文件夹应该是web 文件夹,在此之外的所有内容都应该被禁止访问,所以我会说这是正常行为。我建议将所有这些脚本从 node_modules 复制到 web/scripts 例如 - 手动,甚至更好,使用 gulp 或其他 js 工具。

    【讨论】: