angularjs-service

$watch not detecting changes in service variable

元气小坏坏 提交于 2020-01-17 03:35:48
问题 I am new to angularjs and I am facing this strange problem where $watch is not firing on change of a variable in service. I don't know where I have made a mistake. Plunkr: Link to Plunkr script.js file: var app = angular.module("app", []); app.factory("loggedInUser", [loggedInUser]); function loggedInUser() { var currentLoggedInUser = undefined; setTimeout(function() { currentLoggedInUser = "Karthik"; console.log("Updated user name"); }, 3000); return { getLoggedInUser: function() { return

Angular js promises chaining

…衆ロ難τιáo~ 提交于 2020-01-17 03:10:47
问题 Ive been trying to figure out promises for the last two days and i gotten this so far. Any guided direction would be great as i think i confused my self. So this is my service, it has to run in order with a timeout after image capture for the server to update: returnImage: function() { var results = {}; function getCameraDirectory(){ // Get directory infomation from camera var list = []; deferred = $q.defer(); console.log("getCameraDirectory"); $http.get(BASE_URL + IMAGE_URL).then( function

AngularJS directive and pulling data from a service

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-15 15:32:23
问题 I am trying to figure out the correct way to pull data into my directive from a service. For some reason my $watch statement isn't triggered when the data is loaded. link: function(scope, element, attrs){ scope.loadtext = testService.getJSON(); scope.$watch(scope.loadtext, function(newValue, oldValue){ if (newValue !== oldValue){ alert("watch working"); element.addClass("red"); element.html(newValue.ok); } }); } Simple JSFiddle http://jsfiddle.net/jamesamuir/m85Ka/1/ However, I am not sure if

AngularJS directive and pulling data from a service

丶灬走出姿态 提交于 2020-01-15 15:31:07
问题 I am trying to figure out the correct way to pull data into my directive from a service. For some reason my $watch statement isn't triggered when the data is loaded. link: function(scope, element, attrs){ scope.loadtext = testService.getJSON(); scope.$watch(scope.loadtext, function(newValue, oldValue){ if (newValue !== oldValue){ alert("watch working"); element.addClass("red"); element.html(newValue.ok); } }); } Simple JSFiddle http://jsfiddle.net/jamesamuir/m85Ka/1/ However, I am not sure if

ngModel' deep objects creation mechanism

风格不统一 提交于 2020-01-15 05:36:07
问题 I want to use angular' mechanism for deep property nesting , something that ng-model directive is using. I mean we can create very "deep" object in a scope by writing : ng-model="data.obj1.prop2.attr3.value4.text" in a view , so i want to do it easily in a controller/service too. I don't want to reinvent a wheel (or use this or this). Is there something undocumented like angular.create(path_str) ? 回答1: One way you can achieve is by using $parse service. It has getter and setter function that

Sharing data between AngularJS services

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-10 11:52:01
问题 Is there a way to share data between services in AngularJS? Use case: data aggregation from different services For example I want a service1 that loads some data from a REST Service. Then another service2 adds additional data to the service1 data from another REST API to create a data aggregation service. I basically want to separate the services based on the APIs that they use, but still have a service that holds all the data in the end. 回答1: Create a third service that uses the $q deferred

Sharing data between AngularJS services

会有一股神秘感。 提交于 2020-01-10 11:48:11
问题 Is there a way to share data between services in AngularJS? Use case: data aggregation from different services For example I want a service1 that loads some data from a REST Service. Then another service2 adds additional data to the service1 data from another REST API to create a data aggregation service. I basically want to separate the services based on the APIs that they use, but still have a service that holds all the data in the end. 回答1: Create a third service that uses the $q deferred

Sharing data between AngularJS services

橙三吉。 提交于 2020-01-10 11:48:10
问题 Is there a way to share data between services in AngularJS? Use case: data aggregation from different services For example I want a service1 that loads some data from a REST Service. Then another service2 adds additional data to the service1 data from another REST API to create a data aggregation service. I basically want to separate the services based on the APIs that they use, but still have a service that holds all the data in the end. 回答1: Create a third service that uses the $q deferred

Passing a JS-Class to AngularJS(1.4.x) service to use its variables and functions

柔情痞子 提交于 2020-01-06 15:17:28
问题 I use angularJS(1.4) for frontend only. I have passed the JS-class DummyClass to an angularJS-Service called TLSService , and I added this service to an angularJS-Controller named mLxController . I'm having problems accessing variables and methods of the DummyClass from the mLxController . For example, as you will see in the code below, I can't retrieve a class variable String. I use window.alert(String) to check that. Instead of the String from the DummyClass , 'undefined' is displayed in

unable to display the http get response from the factory in controller in Angularjs application

雨燕双飞 提交于 2020-01-06 01:34:46
问题 In my service I making http get request as shown below: .factory('InvoicesGeneralService', function ($http) { return { getAgreementsByCourierId: function (courierId) { console.log("Courier in Services" + courierId); return $http.get('/api/agreements/byCourierId', {params: {courierId: courierId}}).then(function (response) { return response; }); } }; }); And in browser console I am seeing the following response : [ { "id":3, "number":"AGR53786", "ediNumber":"EDI7365", "startDate":"2012-09-02",