angularjs-scope

How to clear or stop timeInterval in angularjs?

有些话、适合烂在心里 提交于 2019-12-17 08:10:09
问题 I am making a demo in which I am fetching data from the server after regular intervals of time using $interval Now I need to stop/cancel this. How I can achieve this? If I need to restart the process, how should I do that? Secondly, I have one more question: I am fetching data from the server after reqular intervals of time. Is there any need to use $scope.apply or $scope.watch ? Here is my plunker: app.controller('departureContrl',function($scope,test, $interval){ setData(); $interval

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

Model in a modal window in angularjs is empty

非 Y 不嫁゛ 提交于 2019-12-17 07:53:46
问题 Hello I am using angularjs ui bootstrap and I have one text field in a modal window, which when I try to print it in alert window it is empty. Any reasons why? Here is a plunker of the code. 回答1: Try to change the $scope.testField into $scope.myModel.testField (or user.firstName ...) As mentioned in this video angular JS - best practice (29:19): "Whenever you have ng-model there's gotta be a dot in there somewhere. If you don't have a dot, you're doing it wrong." See updated plunker http:/

Call a method of a controller from another controller using 'scope' in AngularJS

这一生的挚爱 提交于 2019-12-17 07:13:01
问题 I am trying to call a method of second controller in first controller by using scope variable. This is a method in my first controller: $scope.initRestId = function(){ var catapp = document.getElementById('SecondApp'); var catscope = angular.element(catapp).scope(); catscope.rest_id = $scope.user.username; catscope.getMainCategories(); }; I am able to set the value of rest_id but I cannot call getMainCategories for some reason. The console shows this error: TypeError: Object # has no method

Call a method of a controller from another controller using 'scope' in AngularJS

a 夏天 提交于 2019-12-17 07:12:33
问题 I am trying to call a method of second controller in first controller by using scope variable. This is a method in my first controller: $scope.initRestId = function(){ var catapp = document.getElementById('SecondApp'); var catscope = angular.element(catapp).scope(); catscope.rest_id = $scope.user.username; catscope.getMainCategories(); }; I am able to set the value of rest_id but I cannot call getMainCategories for some reason. The console shows this error: TypeError: Object # has no method

Dynamic form name attribute <input type=“text” name=“{{ variable-name }}” /> in Angularjs

流过昼夜 提交于 2019-12-17 06:47:11
问题 How would someone use formName.inputName.$valid when the "inputName" was dynamically created? <form name="formName"> <input ng-repeat="(variable) in variables" type="text" name="variable.name" ng-model="variable.name" required /> </form> The output of the HTML input attribute 'name' would be the string "variablename", which would applied to ALL repeated inputs. If we tried this <form name="formName"> <input ng-repeat="(variable) in variables" type="text" name="{{ variable.name }}" ng-model=

Why is using if(!$scope.$$phase) $scope.$apply() an anti-pattern?

别来无恙 提交于 2019-12-17 05:35:27
问题 Sometimes I need to use $scope.$apply in my code and sometimes it throws a "digest already in progress" error. So I started to find a way around this and found this question: AngularJS : Prevent error $digest already in progress when calling $scope.$apply(). However in the comments (and on the angular wiki) you can read: Don't do if (!$scope.$$phase) $scope.$apply(), it means your $scope.$apply() isn't high enough in the call stack. So now i have two questions: Why exactly is this an anti

Angularjs: call other scope which in iframe

扶醉桌前 提交于 2019-12-17 04:53:56
问题 In my test, given 2 document, A and B. In A document, there is an iframe, the iframe source is B document. My question is how to modify B document certain scope of variable? Here is my code: A document <html lang="en" ng-app=""> <head> <meta charset="utf-8"> <title>Google Phone Gallery</title> <script type='text/javascript' src="js/jquery-1.10.2.js"></script> <script type='text/javascript' src="js/angular1.0.2.min.js"></script> <script> var g ; function test($scope,$http,$compile) { $scope

How do I inject a controller into another controller in AngularJS

梦想的初衷 提交于 2019-12-16 22:35:37
问题 I'm new to Angular and trying to figure out how to do things... Using AngularJS, how can I inject a controller to be used within another controller? I have the following snippet: var app = angular.module("testApp", ['']); app.controller('TestCtrl1', ['$scope', function ($scope) { $scope.myMethod = function () { console.log("TestCtrl1 - myMethod"); } }]); app.controller('TestCtrl2', ['$scope', 'TestCtrl1', function ($scope, TestCtrl1) { TestCtrl1.myMethod(); }]); When I execute this, I get the

AngularJS 1.5+ Components do not support Watchers, what is the work around?

笑着哭i 提交于 2019-12-16 20:16:55
问题 I've been upgrading my custom directives to the new component architecture. I've read that components do not support watchers. Is this correct? If so how do you detect changes on an object? For a basic example I have custom component myBox which has a child component game with a binding on the game . If there is a change game within the game component how do I show an alert message within the myBox? I understand there is rxJS method is it possible to do this purely in angular? My JSFiddle