logo
down
shadow

Why does my scope update my factory and my factory update my scope when it should not?


Why does my scope update my factory and my factory update my scope when it should not?

By : user2951006
Date : November 17 2020, 11:58 AM
To fix this issue This is happening because you are making $scope.events = events in your controller instead of $scope.events = angular.copy(events);
(you could instead make the copy in your service, which would be more DRY)
code :


Share : facebook icon twitter icon
AngularJs $scope doesn't update after a GET request on a factory

AngularJs $scope doesn't update after a GET request on a factory


By : Adi Ben-Aroya
Date : March 29 2020, 07:55 AM
help you fix your problem I have been trying AngularJS for a experimental project and I came along with this problem. In my html I want to display a list of items , Using a watch for that is kinda ugly.
try this:
code :
datModule.factory('datfactory', function ($http, $q){

    this.getlist = function(){            
        return $http.get('http://localhost:61686/getdatlist?format=json',{'Access-Control-Allow-Origin': 'localhost:*'})
            .then(function(response) {
              console.log(response); //I get the correct items, all seems ok here
              return response.data.itemsToReturn;
            });            
    }
    return this;
});

datModule.controller('datlist', function ($scope, datfactory){
    datfactory.getlist()
      .then(function(arrItems){
         $scope.items = arrItems;
       });
});
Angular : Update scope from factory not working

Angular : Update scope from factory not working


By : user3267720
Date : March 29 2020, 07:55 AM
I hope this helps you . You can't return from an AJAX call, it async! Instead, return the actual $http request and use .then and assign your data in the controller
code :
getListeIncendies : function() {
    return $http.get(site_url+'gestionnaireFeu/listeIncendies').then(function(result) {
        // si liste retournée, on enregistre
        return result.data;
    }, function(err) {
        console.log("Un problème est survenu. (service incendie : getListeIncendies).");
    });
},
Incendie.getListeIncendies().then(function(data) {
    $scope.incendies = data;
});
AngularJS : Getting data from Factory and update Controller scope and view

AngularJS : Getting data from Factory and update Controller scope and view


By : Radhi Manne
Date : March 29 2020, 07:55 AM
wish helps you As you are doing async $http call then that data would not be available at that instance of time. It would be available when ajax call succeeded. You need to use .then function which will create a promise chain and will execute a function when .success function returns a data.
Controller
code :
sp.controller('HomeCtrl',['$scope','homeFeed','$window',
   function($scope,homeFeed,$window){
     //getting all the home feed data
     homeFeed.getFeeds(JSON.parse($window.localStorage['SP-User']))
     .then(function(data){
        $scope.feeds = data 
     });
   }
]);
Angular factory: update scope with progress during upload

Angular factory: update scope with progress during upload


By : opekope2
Date : March 29 2020, 07:55 AM
Hope that helps @Dmitry Tolmachov answer would definitly work but I would have used the defer.notify because you are already using a promise and because using the notify you do not need to manually call the digest cycle :
code :
fileTransfer.onprogress = function (progressEvent) {
    if (progressEvent.lengthComputable) {
        progress = (progressEvent.loaded / progressEvent.total) * 100;
        console.log(progress);
        defer.notify(progress);
    } else {
        //loadingStatus.increment();
    }
};
Angular - Update scope when change in Factory data

Angular - Update scope when change in Factory data


By : Dmitri Vlassov
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further If you're not 100% set on using $watch, a pattern that I prefer is to bind new instances of (not references to) modules to the current scope and keep the controllers strictly as components used for wiring together the project's views and models. This excludes the use of $watch, even for coordinating data across modules. I prefer to use $rootScope's $broadcast, $emit and $on methods within modules/factories (after passing in $rootScope as a service, which may or may not work for all situations, though it has for all that I've come across) rather than the comparatively sluggish $watch or $watchCollection methods. Using the latter makes me feel dirty inside... But I digress.
Would something like the following work in your situation?
Related Posts Related Posts :
  • AngularJS - Does $resource requests send cookies automatically?
  • Communication between two nested directives angularjs
  • what can or cannot be done with a controller created in a module Vs controller created globally?
  • Angularjs - add ng-* attributes using directives
  • Why are my Angular, absolute path, URL's not compiling properly with Closure Compiler?
  • AngularJS routing not working properly in PhoneGap
  • AngularJS: Create new scope variable name using a variable value
  • Directive scope update does not update controller scope (AngularJs)
  • Unit-test a angular controller function in a directive
  • jQuery Sparkline in a cell in ng-grid using CellTemplate and Directive
  • AngularJS determine filter in controller
  • How to deploy an app using ionic framework to Amazon? (elastic beanstalk prefered)
  • Conditional injection of a service in AngularJS
  • Filtering on object properties not working
  • Open $modal from the service and pass variables to the controller
  • ngClick evaluated against scope instead of isolateScope
  • onEnter and onExit are not called when state is left/activated in angularjs ui router
  • Shared client & server modules with angularjs and pongular
  • Getting the angular app to run when using protractor
  • Angularjs: create a link for download different types of file
  • AngularJS: On Change of Parent DropDown Option Also Changes the Dependant Drop Down Options Associated with Other Parent
  • Angular HTML5 mode, Wordpress, Rewrites, Apache and You
  • Using angular js form validations in <form:input> tag
  • AngularJS call common functions in a directive template
  • AngularJS Promise resolved incorrectly
  • properly clearing whole AngularJS ui-grid chart
  • Can not figure out how to store $rootScope in angular.bootstrap
  • animate.css animation within angularjs 1.3 using ngAnimate gives different animations in Firefox
  • Auth0 IE Issue: Unable to get property 'frames' of undefined or null reference
  • Am I misusing directives with too much logic?
  • Use an Angular JS value as a parameter of TWIG "path" function in Symfony 2
  • multiple function on ng-click angularjs
  • Converting $.ajax call to $http call in angular 404 error
  • Angularjs templateUrl file location not found
  • How to execute the function after change page in angularjs?
  • Pass variable to AngularJS directive without isolated scope
  • OAuth, Custom Login, or Both
  • Angular Directive: Isolate Scope & Transclude is true, but HTML in the directive needs to continue to bind to parent
  • Compare objects in angularjs
  • Combine "Checkbox" & "Avatar" in an Ionic Framework List
  • Issue with the Angular UI router when inheriting from a parent state
  • Is there a way to initialize an Angular Service without DI into controller
  • Why is a parent controller's $scope not accessible from a (child) directive?
  • How to get back button in Ion-tabs page
  • AngularJS bind class attribute to model
  • How can I get AngularJS ui-router to respond correctly to a browser page refresh?
  • Angular validation does not work
  • Breez Create Complex Entities
  • Drag and drop using protractor in dthmlx component
  • In Angular JS, what is the default 'cache' value that is used when sending request with $http service?
  • How to change placeholder for single textbox in angular?
  • $ is not defined - jquery angular mixing
  • CORS issue angularjs and spring security
  • Angularjs cannot select last item in dropdown the first time
  • Angularjs - $watch issue
  • On change radio button to no the span should hide in angular
  • Creating a wordcloud generator in Angularjs
  • Angular UI Bootstrap collapse - whats wrong?
  • AngularJS after redirect from app to app, the default page is not loading
  • AngularJS testing $httpBackend.whenGET().respond() not working with number as parameter
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org