angularjs-service

Is there a loosly coupled way to update a parent directive from a dynamically created view/controller that is a child of the parent

☆樱花仙子☆ 提交于 2019-12-05 22:39:10
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 directive with an isolated scope. I want the views to be loosely coupled to their parent window and not have to something like $scope.$parent module.directive('window', function() { return { restrict: 'E', replace: true, templateUrl: 'windowTemplate.html', controller: 'windowController', scope: { config: '=' }, link: function(scope, element, attrs) { } }; }); module.directive('view', function($compile,

Angularjs - equal sign in $http post data

纵然是瞬间 提交于 2019-12-05 21:38:44
I'm using angularjs' $http service to post data to my API. It works great.. until I add and equals sign to the contents of data (JSONRequest in example) var request = { 'method': 'POST', 'url': API_URL + apiActionName, 'data': JSONRequest, 'withCredentials': true, }; $http(request). success(function(data, status, headers, config) { // handle success }). error(function(data, status, headers, config) { // handle error } this works for data contain the following JSONRequest { 'text':'this is some text' } however when the data contains this { 'text':'this is = some text' } the request is escaped

ui-route resolve not working

二次信任 提交于 2019-12-05 18:00:16
My Application needs a some basic data to start. That's why i created a service and I am using it as model for that common data so that it can be accessible to all the controllers. I am trying to resolve the service using ui-route's reslove functionality that says if I return a promise then it will be resolved before the controller's execution begin but it is not working for me. here is my code service: var Data = function ($q, $http) { var list = {}; var cachedData; var resolveData; resolveData = function () { return $http.get('/api/data') .then(function (response) { var deferred = $q.defer()

Inject dateFilter in a service in AngularJs

╄→гoц情女王★ 提交于 2019-12-05 08:31:42
问题 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 // What I want console.log(dateFilter(new Date(), 'yyyy-MM-01')); // ..... Some code }]); So I would like to know if it is possible to inject a filter in a service or maybe it is accessible in another way. And if you have a link to a documentation about this point, it would be really nice :) Been searching

AngularJS inject service mock inside service tests

与世无争的帅哥 提交于 2019-12-05 05:33:34
I have been trying to test a service to no avail for some time now and was hoping for some help. Here is my situation: I have a service looking a little like this myModule.factory('myService', ['$rootScope', '$routeParams', '$location', function($rootScope, $routeParams, $location) { var mySvc = { params: {} } // Listen to route changes. $rootScope.$on('$routeUpdate', mySvc.updateHandler); // Update @params when route changes mySvc.updateHandler = function(){ ... }; ... ... return mySvc; }]); And I want to mock the services injected into 'myService' before the service gets injected into my

AngularJS factory property isn't being updated in $scope when not using push()

北城余情 提交于 2019-12-05 03:58:50
I have a factory that is retrieving the data from an external source. As soon as i get the data, i use a second factory to filter it by a certain criteria. The factory property is assigned to scope. Now when i do this in my factory, it doesn't update the scope: factory.foo = [{id:1,name:'foo'}]; // doesn't work therefor also the filterin in a second factory doesn't work factory.foo = Filter.filter(); // doesn't work while this works: factory.foo.push({id:1,name:'foo'}); // works Does anyone have an idea if this is intended and why it is like this, and how to solve it? Full Sample plus plunkr

Getting AngularJS Error: “[$rootScope:inprog] $digest already in progress” without a manual $apply

风格不统一 提交于 2019-12-05 01:25:25
Other posts on this error always include someone trying to $apply without using a safe apply, but that's not the case in my example. My function IS successfully returning the data I requested from the API, but I can't clean this bug and it's driving me nuts. Every time before the .success is called in my $http function I get "Error: [$rootScope:inprog] $digest already in progress" in the console. Below are my controller and service. Thanks! Here's my service including a function to post an $http call with a payload: Services.service( 'CoolService', ['$q', '$rootScope', '$http', 'Auth',

Angular modal dialog best practices

佐手、 提交于 2019-12-04 21:11:57
问题 What is the best practice for creating modal dialogs with dynamic content, contrasted with dialogs that don't have dynamic content. Eg.. We have some modal forms that accept a list of form elements, and have submit/cancel. Also, there are modal dialogs that just display a confirm/ok type of operation. I've seen a lot of people saying that dialogs should be services passed into the controller, but it seems to me that services shouldn't be rendering UI components and manipulating the DOM. What

AngularJS $http POST request different results with then and success

僤鯓⒐⒋嵵緔 提交于 2019-12-04 19:35:52
Something is driving me nuts; maybe someone can help me out with the following? : I am using AngularJS 1.2.26 (have to because IE8 needs to be supported) I have to invoke some backend services that were initially build for a backbone frontend. I managed to do that in the following way: $http({ method: 'POST', url: url, headers: {'Content-Type': 'application/x-www-form-urlencoded'}, transformRequest: this._transformRequest, data: formData }) .success(function (data) { // bla bla not relevant }).error(function (error) { // bla bla not relevant }); Now i try to work with the then function as i

Angular JS Unknown Provider Error

点点圈 提交于 2019-12-04 15:03:17
I am getting this error in my angular js app and can't figure out what's causing the problem. It seems to be a common issue but all my troubleshooting hasn't helped at all. If anyone can point to waht the problem may be it would be appreciated. Thanks :) Error: [$injector:unpr] Unknown provider: ResultsServiceProvider <- ResultsService <- ResultsController Here is my code: app.js angular.module('resultsApp', ['ngRoute', 'nvd3', 'ngResource']) .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/results', { controller: 'ResultsController', templateUrl: 'app/results