Routing.generate() module (FriendsofSymfony/FOSjsRouting Bundle) - angularjs

I am trying to create a multiple input tags-input field in AngularJS, where I also want to add auto complete, so that on typing atleast 3 letters in the input field, the already existing tag names in the database appear as suggestions in the dropdown.
Here is the problem:
I am using Routing.generate() module of the FOSjsRouting Bundle to call the controller action inside the javascript code (the action in-turn returns the following JsonResponse object):
Here is the 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
FROM AppBundle:Tag t
WHERE t.id > :id
ORDER BY 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 is the 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'));
};
});
Here is the result I get:
Now when I save the Json response in tags.json and call it 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');
}
});
I get the perfectly working result:
Now I know the problem lies with proper usage of Routing.generate(). Since I am new to AngularJS and am just learning how to debug in console(which m loving by the way), m not entirely sure if I can figure out the problem on my own. Any help is appreciated.
n m sorry the post became too long, just wanted to make it clear.
So, awaiting response...

This is not a problem with AngularJS, this is a problem of variable scope in JavaScript.
Did you import the scripts in your HTML as specified in the documentation?

Related

Assign C# MVC View variables to AngularJS

I am getting object not set to instance during page load inside angularJs code
View
#model IAAS_Application.Models.ManageModels
#{
ViewBag.Title = "IAAS";
Layout = null;
}
My Angular Module
var app = angular.module('R1_myApp', []);
app.controller('R1_myCtrl', function ($scope, $http, $window, $compile) {
$scope.initEditModeData=function(){
debugger;
if(1==0){
$scope.PP.Private =(#Model.PP==null)?false:#Model.PP.Private;
$scope.PP.Public = (#Model.PP==null)?false:#Model.PP.Public;
$scope.PP.Cust_Name= (#Model.PP==null)?"":#Model.PP.Cust_Name;
$scope.PP.Cust_Flag=false
}
};
});
I am getting this error
I have put Null condition to make sure it doesn't enter inside. But by default while page load, control enters in and gives error.
What am I missing? can anyone help me?
I tried inititializing the object in c# MVC code and then send it it view. It worked. I am not getting error now.
obj.PP = new PP();
Return view(obj)

firebase+ angular orderby query not working

Am getting this error performing this query with firebase, well not error but it not returning anything.
This is the factory
.factory("items", function($firebaseArray) {
var itemsRef = new Firebase("https//*****.firebaseio.com/comments");
return $firebaseArray(itemsRef);
})
and in my controller this is how am calling .using the orderby property/attribute
.controller('tdCtrl', function($scope, FeedList, $firebaseArray, $firebase,
$stateParams, dataStore, feedSources, $ionicModal, items) {
$scope.items=items //working when am calling normally
but now i want get all the comment with the hashkey 3432 -- which is dynamic but used as 3432 for easier explanation
$scope.items = items.orderByChild("hashKey").equalTo(3434).on("child_added",
function(snapshot) {
});
this is the post function
.........
$scope.comment.hashkey=3432;
$scope.items.$add(comment);
.............
Solved - guess read all docs before attempting anything with firebase , alot of deprecated code used by most blog tutorial , so docs first :)
var fireRef= new Firebase("https//****.firebaseio.com/comments");
$scope.items = $firebaseArray(fireRef.orderByChild("hashKey").equalTo(id).limitToLast(10));

Cookie-Issue in Angular

i try to store Data in Cookies in Angular. It doesnt seem to work somehow.
I made this function to store the cookie
Store the cookie
$scope.goLove = function(name,id){
var thebestCity = name;
var bestCityID = id;
alert("Du magst: " + thebestCity + " mit der ID: " + bestCityID);
$cookies.put('favourite', thebestCity);
var favouriteCity = $cookies.get('favourite');
alert(favouriteCity);
}
Since the alert works i would think the data is stored inside the cookie. So i tried to open it with another function:
Access the cookie (not working)
cityApp.controller('cookieReader', function($scope, $cookies){
$scope.tellmeCookie = function($scope, $cookies){
var cookieInfo = $cookies.get('favourite');
alert(cookieInfo);
}
});
Somehow the function keeps breaking.As soon as i put the $cookies.get inside there is no more response! Could you please tell me why? Thank you very much!
Firstly have you include angular-cookies.js
Has the module been included in your app
angular.module('app', ['ngCookies']);
On your example that isnt working it kind of looks like your trying to make your code minify safe
you could change it to something like this
cityApp.controller('cookieReader',
["$scope", "$cookies", function($scope, $cookies){
$scope.tellmeCookie = function(){
var cookieInfo = $cookies.get('favourite');
alert(cookieInfo);
}
}]
);

Service is not getting hit

Hi I am new to angularjs and am trying to get some information from a service call using Restangular, I am facing trouble while retrieving the data. Following is the code for the js file
angular.module('sol.user', ['restangular'])
.controller('sol.user.UserController',UserController)
.factory('sol.user.UserFactory',UserFactory);
UserFactory.$inject =['$rootScope', 'Restangular'];
UserController.$inject =['$rootScope', 'Restangular','sol.user.UserFactory'];
function UserFactory($rootScope, Restangular) {
alert("1");
var UserController = {};
var userDetails = Restangular.one('/user/userDetails');
var a = userDetails.post();
UserController = a;
return UserController;
}
function UserController($rootScope, Restangular, user){
$state.go('home.search');
}
function RestConfig(RestangularProvider) {
RestangularProvider.setBaseUrl('http://10.98.3.2:9081/CustomerService/');
RestangularProvider.setDefaultHttpFields({cache: false,timeout: 20000});
RestangularProvider.setDefaultHeaders({brand: "wp",userBsb: "032000"});
;
RestangularProvider.setFullRequestInterceptor(RequestInterceptor);
}
I am not able to hit to the service url, while i am able to retrieve the data using RESTClient.
What seems to be the problem?
Also please tell me whats the difference between Restangular.all/one/

Angular + Breeze get entity from metadata without fetching results

Hi there i want to create a form based on the metadata retrieved from breeze to leverage the validation. However, I can't manage to find a way to get specific entity from the Metadata without loading the result.
Is it possible to load 1 entity from metadata and bind it to a view?
I tried using the var entityMetaData = manager.metadataStore.getEntityType(“Order”); but this throws the following exception Heading
Breeze: Unable to locate a 'Type' by the name: 'Order'. Be sure to execute a query or call fetchMetadata first
so i tried to get the entity from the rawMetadata using by fetching it. But this doesn't seem to work as rawmetadata does not have getEntityType function.
(function() {
'use strict';
var controllerId = 'login';
angular.module('app').controller(controllerId, ['$location', 'authcontext','breeze', login]);
function login($location, authcontext, breeze) {
var vm = this;
var manager = null;
var entityTypeName = "Order";
breeze.NamingConvention.camelCase.setAsDefault();
manager = new breeze.EntityManager('http://localhost:54078/breeze/breeze');
manager.metadataStore.fetchMetadata('http://localhost:54078/breeze/breeze').then(function (rawMetadata) {
vm.orderModels = rawMetadata.getEntityType(entityTypeName); //,-- this does not work..
});
}
})();
What could i be doing wrong here?
The metadataStore has the metadata after the MetadataStore.fetchMetadata promise returns. i.e.
manager.metadataStore.fetchMetadata('http://localhost:54078/breeze/breeze').then(function () {
vm.orderModels = manager.metadataStore.getEntityType(entityTypeName);
});

Resources