angularjs-scope

Why does AngularJS execute function on every digest loop?

坚强是说给别人听的谎言 提交于 2019-12-30 07:21:11
问题 I'm coming from Knockout and I'm trying to understand how Angular updates the scope. I'm a bit confused as to why a function defined on the scope (e.g. $scope.doStuff = function() ) gets executed on every single scope refresh. Plnkr link: http://plnkr.co/edit/YnvOELGkRbHOovAWPIpF?p=preview For example: HTML <div ng-controller="one"> <input type="text" ng-model="a"> {{b()}} </div> JS angular.module('test', []) .controller('one', ['$scope', function ($scope) { $scope.a = 'one'; $scope.b =

Angular ngGrid select row on page load

两盒软妹~` 提交于 2019-12-30 04:04:08
问题 My question is an extension to thisquestion Getting select rows from ng-grid? plunker - http://plnkr.co/edit/DiDitL?p=preview I need a row to be selected on page load and I need to avoid listening to 'ngGridEventData' calling $scope.gridOptions.selectRow(2, true); in the controller body fails since the grid has not been loaded. avoiding listening to ngGridEventData is due to the fact that I need the controller to listen to an event triggered before and based on that I need to select the

Angular ngGrid select row on page load

瘦欲@ 提交于 2019-12-30 04:04:06
问题 My question is an extension to thisquestion Getting select rows from ng-grid? plunker - http://plnkr.co/edit/DiDitL?p=preview I need a row to be selected on page load and I need to avoid listening to 'ngGridEventData' calling $scope.gridOptions.selectRow(2, true); in the controller body fails since the grid has not been loaded. avoiding listening to ngGridEventData is due to the fact that I need the controller to listen to an event triggered before and based on that I need to select the

AngularJS animate image on src change

无人久伴 提交于 2019-12-30 02:11:08
问题 I have an AnuglarJS app, where I load/change some images from a webservice... Controller .controller('PlayerCtrl', function($scope, programService) { .... programService.refresh(function(data) { $scope.program = data; }); .... Template <img src="{{program.image}}" /> When my app updates from the webservice the images changes as expected, I just want to make an fadeout / fadein when this happens, how can that be done? Is it possible to always make a fadeout/in when a image src changes? 回答1:

How to stop $broadcast events in AngularJS?

自古美人都是妖i 提交于 2019-12-30 01:36:07
问题 Is there a built in way to stop $broadcast events from going down the scope chain? The event object passed by a $broadcast event does not have a stopPropagation method (as the docs on $rootScope mention.) However this merged pull request suggest that $broadcast events can have stopPropagation called on them. 回答1: Snippets from angularJS 1.1.2 source code: $emit: function(name, args) { // .... event = { name: name, targetScope: scope, stopPropagation: function() { stopPropagation = true; },

angular iterate over json

[亡魂溺海] 提交于 2019-12-29 07:43:32
问题 So I have a json and I am trying to get all the stats for active users only. when I try to do in a for loop something like this for(var i=0; i < user.User.Stats.data.length; $i++;){ return user.User.Stats[i].active === "1"; } it doesn't work ...however works fine without for loop as long as I am getting only one record return user.User.Stats[i].active === "1"; here is my html <div ng-controller="MyCtrl"> <div ng-repeat="user in _users | filter:isActive"> {{user.User.userid}} </div> </div>

Bindings on directive with Isolate scope not in scope sometimes

两盒软妹~` 提交于 2019-12-29 02:06:06
问题 So I have a directive with isolate scope and a controllerAs pattern. var directive = { restrict: 'E', scope: { something: '=' }, templateUrl: './App/directiveTemplate.html', controller: directiveController, controllerAs: 'vm', bindToController: true } and in the controller I init with a call to a REST service using $http that returns a promise. function directiveController(someService) { var vm = this; // Here vm.something is defined and bound to the appropriate model set where the directive

AngularJS 1.4 directives: scope, two way binding and bindToController

假如想象 提交于 2019-12-28 13:22:33
问题 Update : It must have been something stupid in another part of the code. It works now, so the bindToController syntax is fine. We are using AngularJS 1.4, which introduced a new way to use bindToController in directives. After quite a bit of reading (and maybe not understanding everything), we defined our directive like this: .directive('mdAddress', function mdAddress() { var directive = { restrict: 'EA', scope: {}, bindToController: { address: '=' }, templateUrl: 'modules/address/address

Get DOM element by scope $id

点点圈 提交于 2019-12-28 09:38:21
问题 I understand I can get the scope by element: scope = angular.element($0).scope(); scope.$id; // "003" How do I get reverse: Find the DOM element using the scope $id , such as 003 ? I'd like to do this for debugging purposes. My scope tree shows something and I'd like to identify where it came from. 回答1: Although it's not very sexy each dom node gets a class ng-scope so you could tech do something like this maybe: function getScope(id) { var elem; $('.ng-scope').each(function(){ var s =

How to share the $scope variable of one controller with another in AngularJS?

北战南征 提交于 2019-12-28 05:48:08
问题 I have this: app.controller('foo1', function ($scope) { $scope.bar = 'foo'; }); app.controller('foo2', function ($scope) { // want to access the $scope of foo1 here, to access bar }); How would I accomplish this? 回答1: You could use an Angular Service to share variable acrosss multiple controllers. angular.module('myApp', []) .service('User', function () { return {}; }) To share the data among independent controllers, Services can be used. Create a service with the data model that needs to be