angularjs - Routing.generate() module (FriendsofSymfony/FOSjsRouting Bundle) -
i trying create multiple input tags-input field in angularjs, want add auto complete, on typing atleast 3 letters in input field, existing tag names in database appear suggestions in dropdown.
here problem: using routing.generate() module of fosjsrouting bundle call controller action inside javascript code (the action in-turn returns following jsonresponse object):
here controller code:
/** * @route("/jsondata", options={"expose"=true}, name="my_route_to_json_data") */ public function tagsaction(request $request) { $em = $this->getdoctrine()->getmanager(); $query = $em->createquery( 'select t.text appbundle:tag t t.id > :id order t.id asc' )->setparameter('id', '0'); $tagsdata = $query->getscalarresult(); $response = new response(json_encode($tagsdata)); $response->headers->set('content-type', 'application/json'); return $response; }
here angularjs code:
var app = angular.module('plunker', ['ngtagsinput']); app.controller('mainctrl', function($scope, $http) { $scope.loadtags = function(query) { return $http.get(routing.generate('my_route_to_json_data')); }; });
now when save json response in tags.json
, call without using routing.generate() module:
var app = angular.module('plunker', ['ngtagsinput']); app.controller('mainctrl', function($scope, $http) { $scope.loadtags = function(query) { return $http.get('http://localhost/angulartags/web/js/tags.json'); } });
now know problem lies proper usage of routing.generate(). since new angularjs , learning how debug in console(which m loving way), m not entirely sure if can figure out problem on own. appreciated.
n m sorry post became long, wanted make clear. so, awaiting response...
this not problem angularjs, problem of variable scope in javascript.
did import scripts in html as specified in documentation?
Comments
Post a Comment