angularjs-service

Communicating between controllers in AngularJs

谁都会走 提交于 2019-12-02 04:56:25
问题 I have a simple question: what's the best ('cleanest', 'scaleable') path one should go when it comes to interact between (let's say) two controllers. Would that be to define a service and watch that service's return-value in order to react? I setup a simple example here, where I watch the service's current value: $scope.$watch( function() { return myService.getValue(); }, function(newVal) { $scope.value1 = newVal; }); and update that service's value when one of the buttons is clicked. Can

AngularFire $remove item from Array using a variable in Firebase reference does not work

佐手、 提交于 2019-12-02 02:58:47
I've been struggling with the following problem: I'm trying to delete a 'Post' item from a Firebase Array with the $remove AngularFire method which I have implemented in a Angular Service (Factory). This Post is a child of 'Event', so in order to delete it I have to pass this Service a argument with the relevant Event of which I want to delete the post. This is my controller: app.controller('EventSignupController', function ($scope, $routeParams, EventService, AuthService) { // Load the selected event with firebase through the eventservice $scope.selectedEvent = EventService.events.get(

Communicating between controllers in AngularJs

落花浮王杯 提交于 2019-12-01 23:53:52
I have a simple question: what's the best ('cleanest', 'scaleable') path one should go when it comes to interact between (let's say) two controllers. Would that be to define a service and watch that service's return-value in order to react? I setup a simple example here , where I watch the service's current value: $scope.$watch( function() { return myService.getValue(); }, function(newVal) { $scope.value1 = newVal; }); and update that service's value when one of the buttons is clicked. Can this be done better, smaller, cleaner somehow? What's the best practice here? Cheers. Use service to

Confusion about how the promise returned by $interval works compared to $timeout in Angular

五迷三道 提交于 2019-12-01 22:08:23
问题 I'm having an issue understanding how the promise returned by $interval works in Angular. Let's say in the following example, we have a simple "api" factory with a method called "getStuff" that returns an array with one item. We also have a controller that calls $timeout on that factory: angular.module("app",[]) .factory('api', function(){ return { getStuff: function() { return ["stuff"]; } }; }) .controller('appCtrl', function($scope, $timeout, api){ $timeout(api.getStuff, 1000) .then

Confusion about how the promise returned by $interval works compared to $timeout in Angular

 ̄綄美尐妖づ 提交于 2019-12-01 21:34:02
I'm having an issue understanding how the promise returned by $interval works in Angular. Let's say in the following example, we have a simple "api" factory with a method called "getStuff" that returns an array with one item. We also have a controller that calls $timeout on that factory: angular.module("app",[]) .factory('api', function(){ return { getStuff: function() { return ["stuff"]; } }; }) .controller('appCtrl', function($scope, $timeout, api){ $timeout(api.getStuff, 1000) .then(function(response){ console.log(response); }); }) This will log '["stuff"]' in the console after 1 second,

how to pass an array from angular js to REST service using $resource [duplicate]

感情迁移 提交于 2019-12-01 13:30:26
This question already has an answer here: AngularJS: ngResource and array of object as params to URL 1 answer I am a novice to AngularJs and REST service and want to know how can I pass an array of object to REST-POST call in angular js using $resource. I know how to pass a single parameter but not sure how to pass an array. This is my code for Get call where I am passing a single parameter. Can anyone tell me , how can I achieve the same thing with POST + array. Thanks!! var services = angular.module('myApp.services', ['ngResource']); services.factory('AngularIssues', function($resource){

how to pass an array from angular js to REST service using $resource [duplicate]

青春壹個敷衍的年華 提交于 2019-12-01 11:23:36
问题 This question already has an answer here : AngularJS: ngResource and array of object as params to URL (1 answer) Closed 5 years ago . I am a novice to AngularJs and REST service and want to know how can I pass an array of object to REST-POST call in angular js using $resource. I know how to pass a single parameter but not sure how to pass an array. This is my code for Get call where I am passing a single parameter. Can anyone tell me , how can I achieve the same thing with POST + array.

$watch not working on variable from other controller?

跟風遠走 提交于 2019-12-01 10:40:15
I have one controller which displays a checklist, and stores the selection in an array. My other controller runs an $http.get on the array from the first controller. How do I set a $watch so that whenever the array changes, a new HTTP GET request is sent? My attempt: http://plnkr.co/edit/EaCbnKrBQdEe4Nhppdfa // See plnkr for other controller + FooSelection factory + view function SimpleQueryResCtrl($scope, $http, FooSelection) { $scope.foo_list_selection = FooSelection; $scope.$watch('foo_list_selection', function (newValue, oldValue) { if (newValue !== oldValue) $http.get('/api/' + $scope.foo

AngularJS Service returns undefined

泪湿孤枕 提交于 2019-12-01 09:45:07
I have the following service: app.services.emailService = ['$http', '$sce', function ($http, $sce) { return { getMessage: function(messageId, callback) { $http.get('/api/email/inbox' + '/' + messageId).then(function(response) { response.data.message.updated_at = new Date(response.data.message.updated_at.replace(/-/g,"/")); response.data.message.body = $sce.trustAsHtml(response.data.message.body); return response.data; }); } }; }]; In my controller I am assigning the return value to a $scope.message var so that I can display in the front end. $scope.message is undefined $scope.getMessage =

AngularJS Service returns undefined

心不动则不痛 提交于 2019-12-01 07:37:43
问题 I have the following service: app.services.emailService = ['$http', '$sce', function ($http, $sce) { return { getMessage: function(messageId, callback) { $http.get('/api/email/inbox' + '/' + messageId).then(function(response) { response.data.message.updated_at = new Date(response.data.message.updated_at.replace(/-/g,"/")); response.data.message.body = $sce.trustAsHtml(response.data.message.body); return response.data; }); } }; }]; In my controller I am assigning the return value to a $scope