Search Posts

Category: service

Automating promises in a service

I have some very inefficient code in a service that I would like to streamline. var dayPromise = DayResource.query({ start: dateQueryParam, end: dateQueryParam }).$promise.then(function(response) { if (response.length) { response = response[0]; MealLogResource.query({ … }, function(mealLog) { mealLogDeferred.resolve(mealLog); }); … … … } var dayBack1Promise = DayResource.query({ start: dateQueryParamBack1, end: dateQueryParamBack1 }).$promise.then(function(response) { if (response.length) { response = response[0]; MealLogResource.query({ … }, function(mealLog) { mealLogDeferredBack1.resolve(mealLog); }); } else { // Instantiating new empty day response = […]

How to use angular 1.x services to update one component from another?

So I have a parent component that has a ton of smaller components inside of it. The general idea is that I need one component to take in the data in an input and display it on another component. This is what I have which doesn’t quite work, more details on the problem afterwards: const app = angular.module(‘app’, []); app.service(‘dataService’, function() { let data = { key1: “”, key2: “”, key3: { key4: 0, key5: […]

scope variable can not be setted inside service callback

I have the following code: svcUploadMidia.load(scope.TableId, scope.TableName, function(res) { scope.Midias = res.data; for(var i = 0; i < scope.Midias.length; i++) { scope.Midias[i].conteudoBase64 = “data:image/png;base64,” + scope.Midias[i].conteudoBase64; } }, function(err) { errorHandler(err); }); This code is inside a directive and is called by another directive. But all changes made inside the svcUploadMidia.load callback is not setted in the directive scope.Midias and the ng-repeat in the html still empty. Someone know how can I fix it? Source: AngularJS

Uncaught Error: [$injector:modulerr] Failed to instantiate module

I am getting a “failed to instantiate module” error when trying to inject and use an Angular service that I wrote. I have an HTML page that calls an API. I need to be able to take the return value from the API and store it for use in another controller. Here is the HTML page: <!doctype html> <html ng-app=”auth”> <head> <title>Login AngularJS</title> </head> <body> <div ng-app=”auth” ng-controller=”Login”> <form method=”post” ng-submit=”login()” novalidate ng-controller=”Login”> DBID<input type=”text” […]

Looping through Angular API calls

I have a list of items and I want to pass the selected items to the API and check if that item exists or not. $scope.submitButton = function() { for (var i=0; i < $scope.selectedItems.length; i++) { console.log($scope.selectedItems[i]); // item2 myService.checkItem($scope.selectedItems[i]) .success(data, status, header, config) { var myData = data; console.log(myData); }) } } When I select item2 and click the button, I only want the service to return data for item2 but it returns […]

unable to load dynamic page in view only mode based on condition

In jade file, on particular condition i need to make the field in view only mode. but when i give the condition ng-class=”details.lockedStatus.isLocked ? ‘view’ : ‘editView’” . The page is not fully rendered…… form(name=”mainForm” class=”form-horizontal” ng-class=”details.lockedStatus.isLocked ? ‘view’ : ‘editView'”) md-content(style=””) md-tabs(md-dynamic-height=”, md-border-bottom=”) md-tab(label=’Project Details’) md-content.md-padding h1.md-display-2(style=”color:#315a8e”) Project Infomation md-content(md-theme=’docs-dark’, style=”font-size: 16px; width: 99%;” layout-padding=” class=”border”) div(ng-repeat=”p in details.project_details” class=”col-md-3″ style=”margin-top:10px; margin-top: 10px; float: left;”) md-input-container(style=”” ng-if=”p.type == ‘text'” class=”col-md-12″) label {{p.label}} <span style=”color:#ff0000″ […]

selection value is not reading in angularjs

I have a form, after filling the data in it, I am send it to server through http post method in angularjs, the issue is, it is reading/getting all values except value in the select box, it is reading/getting as null value. <!DOCTYPE html> <html> <head> <title>KunEra ERP</title> <meta charset=”UTF-8″> <meta name=”description” content=””> <meta name=”keywords” content=””> <meta name=”author” content=””> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <!– Booststrap compiled and minified CSS –> <link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”> <!– customized […]

AngularJS SET service variable in controller, and use GET it everywhere else without $watch

Here is my basic service to SET and GET the value: .service(‘companyService’, [ function () { var self = this self.options = {} function CompanyService () { self.setOptions = function (newObj) { self.options = newObj } } return CompanyService() }]) In the global controller I call my $api factory which makes an http request (with promise) to get and set Company Options. I do this only once. .controller(‘global’, [‘$scope’, ‘$http’, ‘$api’, ‘$location’, ‘$translate’, ‘$rootScope’, ‘$timeout’, […]