-1

I have simple page using AngularJS. It loads some data, fills select boxes and should react on choosing values in these select boxes.

It works perfectly with direct link:

http://warcry.ru/codiad/workspace/jw/templates/arena-counter-picks.html

But it doesn't work with Slim routing:

http://warcry.ru/codiad/workspace/jw/public/jw/arena

There's "jw/arena" route in my Slim application.

_http://warcry.ru/codiad/workspace/jw/public/index.php renders
_http://warcry.ru/codiad/workspace/jw/templates/arena-counter-picks.html.

How do I fix this? Thanks for your help.

Edit:

Looks like I've found the cause of this problem. I don't use just Slim, I use it with Twig. And looks like Twig conflicts with AngularJS, because they have similar syntax.

How to couple them together then? Or I shouldn't use them together at all?

Found the answer: AngularJS-Twig conflict with double curly braces

Community
  • 1
  • 1

2 Answers2

0

try the below slim framework 2 example with angularjs select box, it has worked for me:

I have student name table from which i will show student names in select box, so make a table student or any your table:

my index.html file with ng-app is:

<html ng-app="mainApp">
    <head>
        <script type="text/javascript" src="angular.min.js"></script>
        <script type="text/javascript">
        var app=angular.module('mainApp',[]);
        angular.module('mainApp').controller('myCtrl1',function($scope,$http){
         $http({
            method : "GET",
            url : "http://localhost/em/mod.php/devicegrp",
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            }).then(function mySucces(response2) {
            $scope.mydata2=response2.data;
            },function myError(response2) {
            $scope.mydata2=response.statusText;
          });
        });

        </script>
    </head>
    <body ng-controller="myCtrl1">
    <select class="form-control" ng-options="o.id as o.studentnm for o in mydata2" ng-model="valueselected" ></select>selected:{{valueselected}}
    </body>
</html>

And my Slim framework 2 file is like:

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET,OPTIONS,POST,PUT,DELETE');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
require 'vendor/autoload.php';
$app->get('/get', function () use ($app) {
      $sql = "select * from student";
        try {
          $db = getConnection();
          $stmt = $db->query($sql);
          $us = $stmt->fetchAll(PDO::FETCH_OBJ);
          $db = null;
          echo json_encode($us);
        } 
        catch(PDOException $e) {
          echo '{"error":{"text":'.$e->getMessage() .'}}';
        }
      });
  function getConnection() {
  $dbhost="localhost";
  $dbuser="root";
  $dbpass="";
  $dbname="restdb";
  $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);  
  $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  return $dbh;
}

$app->run();

?>

Try like this

lazyCoder
  • 2,544
  • 3
  • 22
  • 41
0

Looks like I've found the cause of this problem. I don't use just Slim, I use it with Twig. And looks like Twig conflicts with AngularJS, because they have similar syntax.

How to couple them together then? Or I shouldn't use them together at all?