Routing with angular and symfony

I have a route problem using symfony and angular. I tried to adapt this tutorial for my project and my symfony backend. But no matter what I do on the html main page or in js angular files, when I check an element (using the chrome tools), my div containing my ng-view is always in the comments. I read on the forums that angularjs comments ng-viewif routes do not work. Can someone help solve this problem?

EDIT: It looks like angular got the route, but cannot restore html partial html, because the console displays me 404 on every html page. Does anyone know where I should put my partial html files?

EDIT 2: I finally found the path to my static html file, but the web server returns me a 403 error (forbidden). Do you know how I can access this file?

Here are the files:

layout.html.twig (main template):

<!DOCTYPE HTML>
<html ng-app="adcApp">
    <head>
        <meta charset="utf-8">
        {% stylesheets filter='cssrewrite'
        'Resources/css/bootstrap.min.css'%}
            <link rel="stylesheet" href="{{ asset_url }}" type="text/css"/>
        {% endstylesheets %}
        {% javascripts
            'Resources/js/jquery-1.9.1.js'
            'Resources/js/bootstrap.js'
            'Resources/js/angular.js'
            'Resources/js/angular-route.js'
            'Resources/js/app.js'
            'Resources/js/Controllers.js' %}
            <script type="text/javascript" src="{{ asset_url }}"></script>
        {% endjavascripts %}
        <title>ADC-WebApp</title>
    </head>
    <body>
    <nav class="navbar navbar-inverse">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" ng-href="">ADC-WebApp</a>
            </div>
            <div>
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="">Plan de production
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="#/Comparaison">Comparaison</a></li>
                            <li><a href="#/Param">Paramètres</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <div class="row">
        <div ng-view></div>
    </div>
    </body>
</html>

app.js:

'use strict';

var adcApp = angular.module('adcApp', ['ngRoute', 'adcAppControllers']);

adcApp.config(function($interpolateProvider){
    $interpolateProvider.startSymbol('{[{').endSymbol('}]}'); //Conflict with twig
});

adcApp.config(['$routeProvider', function($routeProvider)
{
    $routeProvider.when('/OGPP/#/Comparaison',
        {
            templateUrl: 'partials/Comparaison.html',
            controller: 'ComparaisonCtrl'
        })
        .when('/OGPP/#/Param',
        {
            templateUrl: 'partials/Param.html',
            controller: 'ParamCtrl'
        })
        .when('/OGPP',
        {
            templateUrl: 'partials/index.html',
            controller: 'HomeCtrl'
        });
}]);

PHP controller:

class OgppController extends Controller
{
    public function indexAction()
    {
        $content = $this->render('ADCOgppBundle:Ogpp:layout.html.twig');
        return new Response($content);
    }
}

My folder partialis in the same directory as my layout.html.twig (BundleDir / Resources / Views / Bundle). All my controllers are declared, but they just print some text in the console and nothing is printed.

+4
source share
2 answers

So finally I earned it. I am new to angularjs and Symfony, so I will write everything I have done to make my routes work.

1st: angular /#/, . Angular URL-. ( )

2nd: Url angular , dir. , wamp ( ), - "Symfony", : WampInstall/Symfony\src\projectName\BundleName\Resources\views\BundleName\partials, partial dir .

3rd: Apache angularjs GET. . .htaccess .src Symfony. . , -.

.

+2

, Symfony Angular - . , .

, Symfony Routing JavaSripts.

Symfony Angular - Angular html ( Twig). baseUrl , :

<componentName baseurl="{{ app.request.scheme ~ '://' ~ 
app.request.httpHost ~ app.request.basePath }}"></componentName >

templateUrl

    templateUrl: function($attrs) {
                return $attrs.baseurl + 'templates/componentName.template.html';
            }

Voila, , .

0

Source: https://habr.com/ru/post/1568871/


All Articles