angularjs-watch

Dynamically add $watch

梦想与她 提交于 2020-01-06 03:30:28
问题 I have a JSON dataset that each row includes an input value, a small block of JavaScript code used to calculate and a subtotal value that is the result of the input value after an eval() preforms the calculation. The dataset will contain one or more rows. Each input will be repeated onto the page in HTML and a sum of the subtotals will be shown to the user as a total value along with each separate subtotal value. I tried to use $watch and add one for each row in the repeater but I can't seem

Do I need to “unwatch” scope variables when the scope is being destroyed?

隐身守侯 提交于 2019-12-19 05:25:24
问题 Below are the docs from angular. I'm watching several variables that are part of this scope to build up a filter string for ng-grid . When this scope is being destroyed, do I NEED to unwatch them by calling the return value from $scope.$watch , or is the destruction of the scope enough to deal with that? What if the variables being watched were NOT part of this scope? Will I leak memory/cause performance problems if I don't "unwatch" variables that are being destroyed along with the scope.

AngularJS $watch vs $watchCollection: which is better for performance?

我只是一个虾纸丫 提交于 2019-12-17 08:09:14
问题 For watching an object scope variable, is $scope.$watch with objectEquality set to true OR $scope.$watchCollection better? For a $scope object variable (like 15 attributes, some nested 2 levels deep) updated with input elements and ng-model in the view, how bad is $scope.$watch with objectEquality set to true ? Is this a big thing to avoid? Is $watchCollection a better solution? I am looking for easy wins to improve performance on my AngularJS App (I'm still stuck on v1.2.2). // ctrl scope

Watch multiple $scope attributes

假装没事ソ 提交于 2019-12-17 02:34:12
问题 Is there a way to subscribe to events on multiple objects using $watch E.g. $scope.$watch('item1, item2', function () { }); 回答1: Starting from AngularJS 1.3 there's a new method called $watchGroup for observing a set of expressions. $scope.foo = 'foo'; $scope.bar = 'bar'; $scope.$watchGroup(['foo', 'bar'], function(newValues, oldValues, scope) { // newValues array contains the current values of the watch expressions // with the indexes matching those of the watchExpression array // i.e. //

watchcollection swallowing an attribute being watched

柔情痞子 提交于 2019-12-13 08:34:39
问题 There are two attributes selCountry and searchText . There is a watch that monitors these two variables. The 1st one is bound to a select element, other is a input text field. The behavior I expect is: If I change the dropdown value, textbox should clear out, and vice versa. However, due to the way I have written the watch, the first ever key press (post interacting with select element) swallows the keypress. There must be some angular way of telling angular not to process the variable

Consecutive writings to several files in the server

谁都会走 提交于 2019-12-12 05:53:25
问题 (* As my previous question has been more or less answered, and the code has evolved, I open a new question. *) I want to build a simple playground with MEAN stack that mimics plunker: we have a list of files and a textarea on the left hand, and a live preview on the right hand. Note that the files are saved in a temporary folder, and the live preview is an iframe injected by the files from that temporary folder. ********** what I have written ********** In the html file, I add one controller

Angular's $http.post doesn't work, nor does its' $http… but jQuerys ajax does. Why?

北战南征 提交于 2019-12-11 05:20:49
问题 For some reason this: return jquery.ajax('my url', { crossDomain : true , data : JSON.stringify({"brand": self.current}) , type : 'POST' }).success(function(data){ scope.results = data; }); and/or this: curl -X POST -H "Content-Type: application/json" -d '{"brand":"target"}' myUrl work fine, but this: var req = { method: "POST" , url : "my url" , data : JSON.stringify({"brand": self.current}) }; return $http(req). success(function(data){ scope.results = data; }); fails miserably with "OPTIONS

AngularJS : $watch within directive is not working when $rootScope value is changed

此生再无相见时 提交于 2019-12-11 03:37:20
问题 I have created an application is angularjs in which i am having a directive, i am ahving a watch within the directive to trigger some methods within the directive when there is a change in $rootScope variable, but the problem is when the $rootScope.name value is changed the watch which is within the directive is not working My code is as given below Working Demo var module = angular.module('myapp', []); module.controller("TreeCtrl", function($scope, $rootScope) { $scope.treeFamily = { name :

watch factory variable with Angular

我的梦境 提交于 2019-12-07 02:50:34
问题 My single page application has 2 controllers : the first is for my main menu and the second is for the view. They share data with this factory myApp.factory('MenuFactory', function(){ var factory = { Monitor: "doneJob", Control: "", Report: "", Display: "", setMonitor: function(value){ factory.Monitor = value; }, setControl: function(value){ factory.Control = value; }, setReport: function(value){ factory.Report = value; }, setDisplay: function(value){ factory.Display = value; } }; return

watch factory variable with Angular

若如初见. 提交于 2019-12-05 05:46:05
My single page application has 2 controllers : the first is for my main menu and the second is for the view. They share data with this factory myApp.factory('MenuFactory', function(){ var factory = { Monitor: "doneJob", Control: "", Report: "", Display: "", setMonitor: function(value){ factory.Monitor = value; }, setControl: function(value){ factory.Control = value; }, setReport: function(value){ factory.Report = value; }, setDisplay: function(value){ factory.Display = value; } }; return factory; }); I would like to watch change on factory.Control , but i can't make it works. When i try this: