Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在symfony中使用angular ng include加载细枝文件_Javascript_Angularjs_Symfony_Twig - Fatal编程技术网

Javascript 如何在symfony中使用angular ng include加载细枝文件

Javascript 如何在symfony中使用angular ng include加载细枝文件,javascript,angularjs,symfony,twig,Javascript,Angularjs,Symfony,Twig,我是新来的,请推荐这个。我正试图像这样加载ng repeat中的模板,但它显示了错误 跨源请求仅支持以下协议方案:http, 数据、chrome、chrome扩展、https、chrome扩展资源 这是我用于ng repeat和include的代码 <div ng-repeat='item in newItems' ng-include="'MyBundle:Default:Content/event.html.twig'"></div> 您不能简单地从angular

我是新来的,请推荐这个。我正试图像这样加载ng repeat中的模板,但它显示了错误

跨源请求仅支持以下协议方案:http, 数据、chrome、chrome扩展、https、chrome扩展资源

这是我用于ng repeat和include的代码

<div ng-repeat='item in newItems' 
ng-include="'MyBundle:Default:Content/event.html.twig'"></div>

您不能简单地从angular中包含一个细枝文件。Angular希望得到一个url,但不理解您在那里使用的Symfony别名。此外,它根本无法处理细枝

如果您必须使用twig(并且不能仅使用基本的html和Angular),则必须创建一个控制器和一条路由,该控制器和路由将服务于html,简化示例:

# app/config/routing.yml

view_route:
    path: /views/{viewName}
    defaults: { _controller: MyBundle:ViewController:viewAction }




# src/MyBundle/Controller/ViewController.php

<?php

namespace MyBundle\Controller;

class ViewController
{
    public function viewAction($viewName)
    {
        return $this->render('MyBundle:AngularViews:' . $viewName);
    }
}
#app/config/routing.yml
查看路线:
路径:/views/{viewName}
默认值:{u控制器:MyBundle:ViewController:viewAction}
#src/MyBundle/Controller/ViewController.php

我不知道symfony,但您是否有意尝试使用非HTTP协议?
<div ng-repeat='item in newItems' 
     ng-include="'{{ path('view_route', { view: 'Content/event.html.twig' }) }}'"></div>