Tagged Questions
71
votes
6answers
18k views
angular js - configuration for different enviroments
how do you manage configuration variables/constant for different enviroments?
This could be an example:
my rest api it's reachable on localhost:7080/myapi/, but my friend that works on the same ...
10
votes
2answers
5k views
Inject dateFilter in a service in AngularJs
I would like to know if there is a way to inject the filters in a service in AngularJs.
I've been trying
app.factory('educationService', [function($rootScope, $filter) {
// ..... Some code
...
9
votes
2answers
2k views
Call angularjs service from simple js code
I have the following angularjs service:
angular.module('app.main').factory('MyService', ["$http", function ($http) {
return new function () {
this.GetName = function () {
...
8
votes
2answers
779 views
Angular Resource - how to check if a resource instance has any unsaved changes?
I want to be able to tell whether an $resource instance has been modified by the user - that is, whether its current state is different than what has been initially loaded from the server && ...
8
votes
1answer
3k views
AngularJS unexpected token in fromJson()
The following line of code:
var sid = $cookieStore.get('PHPSESSID');
is throwing this error:
SyntaxError: Unexpected token m
at Object.parse (native)
at Object.fromJson ...
7
votes
2answers
2k views
AngularJS, is this way of using service good?
i've this HTML:
<p>Hello {{name}}</p>
and the controller is:
function myCtrl(scope, service) {
scope.name = service.getUsername(); // service.getUsername() return "World!"
}
...
7
votes
2answers
8k views
AngularJS: How to handle success and error call backs with ngResource?
The docs does not give any idea about it.
My REST enpoint might throw error
$scope.delete = function(index) {
Transaction.delete({transactionId: $scope.transactions[index].uuid})
};
I ...
7
votes
3answers
8k views
AngularJS: How to pass values from Controller to Service Method?
I have a controller which is dependent on a TransactionService. One of the method is
$scope.thisMonthTransactions = function () {
$scope.resetTransactions();
var today = new Date();
...
7
votes
1answer
246 views
AngularJS philosophy - controllers as “windows” to services
Sorry for the vague title;
I've been restructuring some of my AngularJS code, trying to be more "Angular" about it, and I've noticed this pattern popping up quite a bit:
app.service("someService", ...
6
votes
1answer
484 views
The better approach to design AngularJS services
I'm writing an AngularJS client application that would interact with a REST server.
To manage the client / server interaction I'm using the $resource abstraction.
Actually I'm writing every resource ...
6
votes
2answers
5k views
Force AngularJS service to return data before loading controller
I have a service in Angular which uses my API to get user information and provides it to my controllers. It's set up like this:
angular.module('myApp', ['myApp.filters', 'myApp.services', ...
5
votes
4answers
4k views
How to mock $window.location.replace in AngularJS unit test?
I've got the following service:
angular.module("services")
.factory("whatever", function($window) {
return {
redirect: function() {
$window.location.replace("http://www.whatever.com");
...
4
votes
1answer
58 views
Is this an AngularJS service masquerading as a factory?
I created an AngularJS factory that I reuse for data access:
app.factory('abstractFactory3', function ($http) {
function abstractFactory3(odataUrlBase) {
this.odataUrlBase = ...
4
votes
1answer
967 views
AngularJS - Deep object' property deletion
I know how to set object' "deep" property with $parse service , like in this post.
But how can i delete a deep property ? Not assign it to null with this:
...
3
votes
1answer
411 views
Dirty checking with shared service between controllers, One way works the other does not?
While attempting to answer a question regarding sharing data between two separate controllers I ran into a question .
I usually use services for for this task and began to create a jsfiddle, but I ...
3
votes
2answers
3k views
AngularJS: open a new browser window, yet still retain scope and controller, and services
I'm writing an angularJS app. In this particular controller, I open a new browser window through the $window.open service. But in the new window, all the $scope variables are lost.
I tried to use ...
3
votes
1answer
152 views
Injecting a primitive type in AngularJS
I'm learning my way around AngularJS at the moment. I've largely got to grips with the way Angular handles dependency injection, but there's a gap I can't find an answer for.
Say I have a service ...
3
votes
1answer
4k views
AngularJS not updating template variable when scope changes
This will be one of those stupid questions that is very obvious to the experts.
I have a websocket pushing data to a service where I'm trying to store the data and have it pushed to a template via my ...
3
votes
2answers
3k views
Angular: Mixing provider and custom service in module's config/run
I'd like to do somtehing like that:
angular.module('app', []).config(
[ '$httpProvider', 'customAuthService',
($httpProvider, customAuthService) ->
...
3
votes
4answers
183 views
What's the difference between this services declaration methods?
what's the best way to declare a service I found this 2 different ways i can't seem to see the difference:
first method:
angular.module('app', [])
.factory('Data', ['$http',function($http){
...
3
votes
1answer
3k views
AngularJS watching service variables
Ok, I'm really struggling with this one. I looked everywhere I could for a solution but didn't find it even though there are quite a few similar questions.
I have a class. I need only one instance, ...
2
votes
2answers
263 views
AngularJS services independent of modules on multiple pages
I have a table of users in the database behind my angular app. I have separate login, registration, and user management views as separate pages.
I want to define a service that keeps a list of user ...
2
votes
2answers
432 views
Issues binding / watching service variable shared between two controllers
I am having a really hard time deciphering what is going on here. I understand the basics of Angular's $digest cycle, and according to this SO post, I am doing things correctly by simply assigning a ...
2
votes
1answer
45 views
AngularJS: What is this directive doing?
I have a some experience with AngularJS and have come across this directive on the web, but it is not like anything I have seen before and I am unable to comprehend what it is doing? Can anyone help?
...
2
votes
3answers
114 views
AngularJS $resource only won't return data
So with a factory I'm making a RESTful GET request using $resource, and I'm not getting the data back.
Initially, I get returned $promise and $resolved: false. $resolved eventually becomes true.
I ...
2
votes
1answer
1k views
AngularJS - Controller resource call not passing parameters to service factory?
In AngularJS, I'm trying to pass a parameter in a controller call to a service factory. However, I can't seem to get the parameter passed. The function always passes what I set to be the default in ...
2
votes
3answers
68 views
unable to get data from $q into scope
I'm trying to bind some data being returned from an API to my scope using promises with $q, I am able to pull the data from the server without any issue (I can see JSON being returned using fiddler) ...
2
votes
1answer
311 views
AngularJS: Cannot Resolve Service in Directive Controller
I'm having trouble resolving a service inside a directive controller.
I'm fairly new to Angular so please excuse me if I'm doing this completely wrong.
I've written a sample app here: ...
2
votes
1answer
22 views
Access shared methods directly from view
In my Angular app, I am consuming an API that delivers images in different sizes depending on the parameters I append to the image request (e.g. ?size=small or ?size=medium).
In order to make it ...
2
votes
1answer
66 views
$watch doesn't seem to work when value is evaluated from a function
I have a repeater that renders gridBlocks. Each of these blocks has a property for "Vote Good", "Vote Bad" or "No vote" (for our purpose). This property controls, among other things, the CSS class of ...
2
votes
2answers
485 views
Access stored data in an Angular factory after a $http call
I am trying to build a factory to act as a staging area for my database models, as well as an api to perform basic CRUD calls. I want to be able to access data by storing it in a service or a factory, ...
2
votes
1answer
62 views
Getting just an object back from an asynchronous call
My goal is
to show a username, which needs to manipulated on a web page. The mnaipulation should be done centrally in a service (MasterDataService). I want to used a scope variable on the screen which ...
2
votes
1answer
118 views
What problems would I run into if I make all Data available to all Controllers?
My AngularJS CRUD application processes it's information over a WebSocket Server. (This was mainly so that updates from one user would get automatically pushed to all users without the need for ...
2
votes
2answers
52 views
Is there a loosly coupled way to update a parent directive from a dynamically created view/controller that is a child of the parent
In my app I have window instances. The app can contain multiple windows and windows can contain multiple views. The views are children of each window instance. The windows and view creator are ...
2
votes
1answer
700 views
AngularJS API call error with $http GET
I'm trying to create a simple app using Angular that will consume my API. I'm using a VM to run the code, and I access it on my computer, so to call the API from my machine I can use cURL or any other ...
1
vote
2answers
3k views
AngularJS: PUT send data with URL but not as JSON data
Here is my UserService
angular.module('userServices', ['ngResource']).factory('User', function($resource) {
return $resource('/users/:userId',
// todo: default user for now, change it
...
1
vote
3answers
36 views
How to create a object with properties that are sharable among controllers in AngularJS?
This is a follow-up question to How to create this global constant to be shared among controllers in Angularjs?
The answer provided allows a constant $webroot to be shared among controllers.
app = ...
1
vote
2answers
1k views
AngularJS service retry when promise is rejected
I'm getting data from an async service inside my controller like this:
myApp.controller('myController', ['$scope', 'AsyncService',
function($scope, AsyncService) {
$scope.getData = ...
1
vote
2answers
187 views
AngularJS cannot connect factory to controller
I'm sorry if this is an easy question. I'm new and probably don't understand the right things to search for to find the answer.
I've basically followed this angularJS tutorial ...
1
vote
1answer
2k views
AngularJS Bind service array variable to controller scope
I have been able to properly bind an object with primitive data from a service to a scope variable from a controller but I'm having trouble doing the same thing with an array variable from the ...
1
vote
1answer
2k views
AngularJS: service query returning zero result
my app.js looks like
var app = angular.module('pennytracker', [
'$strap.directives',
'ngCookies',
'categoryServices'
]);
app.config(function($routeProvider) {
console.log('configuring ...
1
vote
1answer
107 views
Undefined is not a function error when using factory method in angularJS
I'm having problems finding the solution to TypeError: undefined is not a function in my code.
I have the following app.js:
var app = angular.module('test', ['ngRoute', 'test.services', ...
1
vote
1answer
99 views
What is the difference between `value` attribute and `ng-value` attributes in angularjs
What is the difference between value and ng-value attributes in angularjs templates? If I use ng-if on the field using value attribute it works properly but if I change the attribute value to ng-value ...
1
vote
2answers
206 views
AngularJS call common controller function from outside controller
My basic premise is I want to call back to the server to get the logged in user in case someone comes to the site and is still logged in. On the page I want to call this method. Since I am passing ...
1
vote
2answers
87 views
Angularjs: Singleton service using $http [closed]
is it possible in angular to create service using $http which will take method, url, success and failure callback as parameters when called from controller.
I want to achieve following kind of ...
1
vote
1answer
205 views
Angular best practice (in this situation) for passing data between controllers - service or routeParams?
I'm fairly new to AngularJS and I realise this question has been asked before (so hopefully I wont get voted down) but I've been unable to find a question matching my situation.
I want to pass search ...
1
vote
1answer
809 views
AngularJS | Create chained promise
I would like to create a chained promise for my service provider:
this.$get = function($q, $window, $rootScope) {
var $facebook=$q.defer();
$rootScope.$on("fb.load", function(e, FB) {
...
1
vote
2answers
1k views
AngularJS Error: $injector:unpr Unknown Provider
I'm trying to build my own service by following the example in the documentation for the factory methodology. I think I've done something wrong however because I continue to get the unknown provider ...
1
vote
2answers
2k views
AngularJS. Best practice concerning proper two way data binding from a service
I have an 'Account' service which acts as a centralized data storage used in multiple controllers and views. This service will hold, besides getter and setter methods all data associated with two ...
1
vote
1answer
55 views
Can not push an interceptor
In angular js i have made a service that should authenticate user simply it stores a token and send it with every request so i used interceptors.
her is the code of the interceptor.
...