w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Running $apply on $rootScope vs any other scope
Running $digest/$apply on any given scope will visit all other scopes using depth-first traversal: https://github.com/angular/angular.js/blob/3967f5f7d6c8aa7b41a5352b12f457e2fbaa251a/src/ng/rootScope.js#L550-L558 That means that the only difference is that the $digest will start at whatever $scope it was called on

Categories : Angularjs

AngularJS - refresh view after http request, $rootScope.apply returns $digest already in progress
Oh my ! You got the f** matter with AngularJS ! In fact you have to do a "safeApply" like that for example : $rootScope.safeApply = function(fn) { var phase = this.$root.$$phase; if(phase == '$apply' || phase == '$digest') { if(fn && (typeof(fn) === 'function')) { fn(); } } else { this.$apply(fn); } }; In AngularJS you can only have one $apply or $digest loop at the same time. For details on these loops look at the docs : http://docs.angularjs.org/guide/concepts It will explain what is the $apply loop and you'll understand a lot of things about the two-way-data-binding in AngularJS Hope it helps.

Categories : Http

CSS - trying to apply background-image, using ~/ not working
CSS is client based. Basically what your code does is creating a GET request like: http://domain.com/css/~/themes/Modern/images/bg_full.png You probably want something like: background-image:url('/themes/Modern/images/bg_full.png'); since this will result in a request like http://domain.com/themes/Modern/images/bg_full.png

Categories : CSS

AngularJs $scope.$apply not working as expected
Copied from my comment to make it clearer what the problem was: I managed to figure out the problem. When using their example I had a duplicate of ng-controller(Their example was nested within my other controller) and even though both were using the same controller it seems like it would only update anything that was within nested controller scope. When removing the duplicate ng-controller attribute it all works fine.

Categories : Angularjs

Loosing the battle - Datediff working but I want to apply a condition
Try SELECT [faxdate],DAY(DATEDIFF(CAST(SUBSTRING(RPT.FaxDate, 1, 4) + '-' + SUBSTRING(RPT.FaxDate, 5, 2) + '-' + SUBSTRING(RPT.FaxDate, 7, 2) AS DATE), getdate())) AS vDiff instead of using where, use having like below HAVING vDiff > 60

Categories : Misc

C# WinForms - Looping through all controls to apply event handler, not working in SplitContainer?
Assuming that the problem is that you are not assigning the event to every single control on the form (only top-level controls), the fix should be to change your setupFocusControls(Control) method: private void setupFocusControls(Control parent) { foreach (Control control in parent.Controls) { control.GotFocus += HandleFocus; // add the following line to recurse throughout the control tree setupFocusControls(control); } } This will add the HandleFocus event handler to every single control, by recursing through the children of every control. I hope this works for you! As a bonus, if you want to add the event handler to all controls, including the parent control, you could write the setupFocusControls method as follows: private void setupFocusControls

Categories : C#

$rootScope vs top most ng-controller
This is a question very similar to the How to go globals Generally speaking you should try to avoid putting things on a $rootScope as it is AngularJS equivalent of a global window scope. Since the $rootScope can be injected everywhere (services, directives etc.) variables declared on the root scope a truly global. If you've got a top-most, app-level controller and sticking variables in there does the trick for you I would favor this over polluting the $rootScope. As a general rule of thumb we should be using the most restrictive / lower-level scope. Don't forget that a service might be an answer here.

Categories : Angularjs

$rootScope's databinding could not get the right value
You need to inject $scope rather than $rootScope into the controller like this controller('testCtrl', ['$scope', testCtrl]); AngularJS creates a child scope automatically when compiled HTML template is executed. So the ng-model used in the template is in child scope. Since you tried to access the data in the controller, you have to access to the the same child scope as the template.

Categories : Angularjs

$rootScope as event aggregator
Take a look at http://docs.angularjs.org/api/ng.$rootScope.Scope#$broadcast. Using $rootScope as event aggregator is perfectly fine unless you are triggering events outslide digest cycle or triggering multiple (100+) events at the same time where some other solutions may be more appropriate . One accepted practice would be to use namespacing (namespace:event - pattern used by Backbone.Marionette) Use $emit on a child scope instead of $broadcast on $rootScope - $emit propagates only upwards, where $broadcast propagates downwards - to all children

Categories : Javascript

Double $rootScope in Angularjs app
Haven't been able to reproduce your problem - but we've seen similar trouble with double controllers / scope because we accidentally specified the controller twice - once in the routing tables ($routeProvider.when(..., controller="xyzCtrl", templateUrl="xyz.html") and again in my template (data-ng-controller="xyzCtrl"). Removing either one of them fixed the problem. Hope this is a clue in the right direction.

Categories : Angularjs

How do I print $rootScope variable?
Just use {{s3BucketUrl}} and you would get the value. Your current scope is a child scope of rootscope and hence you can always access the elements of rootscope. This wiki is highly recommended

Categories : Javascript

Why $rootScope.$new does not let template into the directive?
According to the docs for $digest (http://docs.angularjs.org/api/ng.$rootScope.Scope), this will only process watchers etc for the current scope and its children. This suggests to me that when you set scope = $rootScope and then $digest you will be processing watchers etc on the $rootScope, I think this is where promises will be resolved too, releasing your templates. When you do scope = $rootScope.$new() and call $digest on that, I expect anything that should happen from the $rootScope doesn't happen. So, does this work if you change scope.$digest() to $rootScope.$digest() or scope.$apply()?

Categories : Angularjs

AngularJS: rootScope in directives scopes
scope: true not isolated, not shared, but a new prototipically inherited scope per directive instance. http://jsfiddle.net/4LAjf/1 You can log the id of the scope with console.log(scope.$id). With scope: {} you'll get, for example, 003 and 004. With scope: false (or nothing), the scope is shared, e.g. both have 002. With scope:true they have different id's but can read $rootScope. In the live example you can see the scope ID in your local variable localName. I named the dummy directive mydir instead of module. It just looks weird naming module a directive. More about AngularJS scopes

Categories : Angularjs

AngularJS GlobalCtrl vs $rootScope vs Service
Generally speaking global variables are considered bad practice, as they don't encourage encapsulation, make debugging difficult, and promote bloated code. Here's a good discussion of global variables: http://c2.com/cgi/wiki?GlobalVariablesAreBad. A good rule of thumb is to add properties and methods to the most local scope possible and use services to share data between modules.

Categories : Javascript

Why do events from provider not $emit to $rootScope?
You are not instantiating validationService therefore the listener does not get attached. Include it in the module and inject it to the controller. angular.module('mine',["mine.services"]).controller('CommitController', [ '$scope', "validationService", function($scope, vs) { $scope.validate = function() { $scope.$emit('request:validate'); }; } ]); angular.module('mine.services',[]).factory('validationService', [ '$rootScope', function($rootScope) { $rootScope.$on('request:validate', function(e) { console.log('received the request:validate event -'+ 'go ahead with validation'); }); } ]); If you don't want to inject the service into controller, you do the binding in module's run method

Categories : Javascript

Angularjs rootscope not updating ngClass
When you define a variable in the root scope, you can't access it in the same way as you define it in the local scope. $rootScope variables can be accessible in the AngularJS templates using $root.<variableName>, so your HTML file should be changed to this: <body> <ng-view ng-class="{ 'splash': $root.splash=='splash' }"></ng-view> </body> You can see the diffrence of $scope and $rootScope in this demo

Categories : Angularjs

Why does a $rootScope.$watch return a value multiple times?
If a side effect of a watch results in a variable change, the watch gets called again until all changes are resolved. So if the action that results in the watch getting triggered (the action that changes someVar) results in other actions that also update someVar, there can be a cascade (up to 10 times before angular says enough?)

Categories : Angularjs

AngularJS - $rootScope property value undefined in service
This should work just fine: var myApp = angular.module("myApp", []); myApp.run(['$rootScope', function($rootScope){ $rootScope.test = 123; }]); myApp.controller('AppController', ['$rootScope', function ($rootScope) { console.log($rootScope.test); }]); Plunker: http://plnkr.co/edit/7NTGOK I guess that you are reading the value before you are writing it. Could you share more code? UPDATE The debugging experience is really weird here. However, in my updated plunker you can see through the timestamps that the writing happens after reading: http://plnkr.co/edit/pn5Wxk

Categories : Javascript

AngularJS - Get reference to $rootscope in child window
If you have an id on your ng-app <div id="app-container" ng-app="myApp"> You can get the $rootScope by: angular.element('#app-container').scope()

Categories : Javascript

R: Split-Apply-Combine... Apply Functions via Aggregate to Row-Bound Data Frames Subset by Class
You've tackled this problem in a way that makes it very hard to debug. I'd recommend switching things around so you can more easily check each step. (Using informative variable names also helps!) The code is unlikely to work as is, but it should be much easier to work iteratively, checking that each step has succeeded before continuing to the next. paths <- dir("C:/Data/", pattern = "\.csv$") # Read in CSV files as data frames raw <- lapply(paths, read.csv, str) # Extract needed rows filter_metrics <- c("MaxTemp", "AvgTemp", "MinTemp") filter_years <- 1970:2000 filtered <- lapply(raw, subset, !is.na(Value) & Year %in% filter_years & Element %in% filter_metrics) # Drop any empty data frames rows <- vapply(filtered, nrow, integer(1)) filtered <- filtered[r

Categories : R

Complex rolling scenario (CROSS APPLY and OUTER APPLY example)
I assume that you have a DimDate table with the following structure: CREATE TABLE DimDate ( DateKey INT PRIMARY KEY ); and DateKey column doesn't has gaps. Solution: DECLARE @NumDays INT = 3; WITH basic_cte AS ( SELECT x.DateKey, d.Name, Amount = ISNULL(f.Amount,0) FROM ( SELECT t.*, CONVERT(INT,CONVERT(CHAR(8),CONVERT(DATETIME,CONVERT(DATETIME,CONVERT(CHAR(8),t.LiveKey,112))+@NumDays),112)) AS EndLiveKey FROM #target t ) d CROSS APPLY ( SELECT dm.DateKey FROM DimDate dm WHERE dm.DateKey >= d.LiveKey AND dm.DateKey < d.EndLiveKey

Categories : SQL

Simplify apply, sapply apply expression on list of matrices
Not sure its any tidier apply(do.call(rbind, unlist(x, FALSE)), 2, max) [1] 383581.5 4635506.3 you can use the functional library not sure if base has these yet require(functional) dumcall <- Curry(do.call, what = 'rbind') doublebind <- Compose(dumcall, dumcall) apply(doublebind(x), 2, max) [1] 383581.5 4635506.3

Categories : R

AngularJS $rootScope.$watch and $http interceptors (for ajaxSpinner directive)
The updates to the $rootScope parameter requestCount is happening outside the cycle of Angular due to the async nature of responses. Use $rootScope.$apply() to fix the issue.

Categories : Angularjs

rails apply where if variable is not nil else apply all - nicer way
You can try something like this @country = Country @city = City if co.blank? @country = @country.where(:id => co) end if ci.blank? @city = @city.where(:id => ci) end @countries = @country.order(:name).all.map{|i| [i.name,i.id]} @cities = @city.order(:name).all.map{|i| [i.name,i.id]}

Categories : Ruby On Rails

How to load some data into $rootScope from remote server before the module's controller is loaded?
The $http service is implemented using promises. The code you write in your success handler will run when the promise is resolved. Due to the asynchronous nature of promises, it is unknown when this happens. It can be 1 second later or 10 seconds later. Meanwhile, your other code continues to run and your controller is probably getting loaded before the promise is resolved. The best way to tackle this problem is to think in 'asynchronous' terms, not force some kind of synchronous behavior. Here are a few valid options: You could move the code to your controller and move your logic to the success handler like this: myModule.controller('SomeCtrl', function($rootScope, $http, $location) { $http.get("http://mydomain/load_user/"). success(function(respData) { // Perform any l

Categories : Angularjs

jQuery fadeIn effect not working its Flicker which apply on 2 divs, but show/hide works perfect need to change bg image with fading effect
You are showing two div, but making fadeIn effect uopn a single one. You need to apply the effect to both, $("#OneDiv").fadeIn(400); $("#Tab1Btn").fadeIn(400); Check this http://jsfiddle.net/yUKdh/7/ Note: Just applied the effect to mouse events of the start#

Categories : Jquery

What's the purpose of setting $rootScope.$state = $state; with angular-ui ui-router?
I don't think this is standard code. The only reason i see these being added to you rootScope it to facilitate binding within the html view everywhere. Else if you want to bind to some property of either $state or $stateParams you would have to inject the $tate and $stateParams service into the controller. Ideally this should be injected into controllers that require this service. If you remove it any html binding dependent on it would fail. Search html views for bindings with name $state and $stateParams and you would find where they are used.

Categories : Angularjs

How do I apply css to only IE 8 and below
Two options: 1: .ui-icon-searchfield:after { background-color: #0000009; /* IE8 and below */ background-color: rgba(0,0,0, 0.4)9; /* IE8 and below */ background-image: url(images/icons-18-white.png)9; /* IE8 and below */ background-repeat: no-repeat9; /* IE8 and below */ -webkit-border-radius: 9px9; /* IE8 and below */ border-radius: 9px9; /* IE8 and below */ filter: alpha(opacity=40)9; /* IE8 and below */ } 2: <!--[if IE 6]> /*According to the conditional comment this is IE 6*/ .ui-icon-searchfield:after {your stuff} <![endif]--> <!--[if IE 7]> /*According to the conditional comment this is IE 7*/ .ui-icon-searchfield:after {your stuff} <![endif]--> <!--[if IE 8]> /*According to the conditional comment this

Categories : CSS

How to apply TDD to web API development
From what you are describing you could easily find yourself writing integration tests. If your aim is to test the logic for processing what is returned from the scraped data (e.g. you know that you are going to get a timetable in a specific format coming in and you now have logic to process that data) you will need to create a SEAM between your web services logic and your processing logic. Once you have done this you should be able to mock the data that is returned from the web service call to always return the same table data and then you can write consistent unit tests against it. public class ScrapingService : IScrapingService { public string Scrape(string url) {// scraping logic} } public interface IScrapingService { string Scrape(string url

Categories : Api

Apply CSS to child DIV only
Try something like this in jQuery: CSS: .hoverableClass:hover { box-shadow: inset 0 0 0 2px red; -webkit-box-shadow: inset 0 0 0 2px red; -moz-box-shadow: inset 0 0 0 2px red; -o-box-shadow: inset 0 0 0 2px red; } JS: function deepSearch(parent){ var b_ClassAdd = true; if (!parent){ parent = $('body'); b_ClassAdd = false; } var allDivChilds = parent.find('div[comp-id]'); if ((!allDivChilds || allDivChilds.length == 0) && b_ClassAdd) parent.addClass('hoverableClass'); else for (var i = 0; i < allDivChilds.length; i++) deepSearch($(allDivChilds[i])); } deepSearch(); This code is untested and just an idea for a solution.

Categories : Javascript

How to apply Prefixfree.js to only a particular Div?
prefixfree scans all included stylesheets and style tags for properties that would need a predfix and applies them. The only way (I know) is to set data-noprefix on those elements (link, style) and use an extra style-tag or stylesheet that'll be prefixed. Seems hacky to me.

Categories : Javascript

Why is apply() not called ?
Tester2 is an object name, a value. Expression may contain only single value. You could replace Tester2 with 2 or "str". Tester2 is an expression with result type Tester2.type. Just like 2 is an expression with result type Int. To call apply method you should add brackets like this: Tester2() You could call apply method explicitly without brackets: Tester2.apply

Categories : Scala

Can't apply shader to OBJ
Good day, I suspect the problem lies with the "tAO" uniform. Instead of: uniforms["tAO"].texture = THREE.ImageUtils.loadTexture("AO.jpg"); change .texture to .value uniforms["tAO"].value = THREE.ImageUtils.loadTexture("AO.jpg"); The GL error may be a consequence of the missing texture map. Otherwise the code looks fine. If all else fails, only enable and push the normal and diffuse maps and see where that gets you to start.

Categories : Javascript

Using .apply() with more than 1 df column
subset before you apply In [151]: df = DataFrame(randn(10,3),columns=list('ABC')) In [152]: df Out[152]: A B C 0 -0.071947 -0.243518 -0.188782 1 -1.028449 0.525397 1.629097 2 0.302620 -0.530769 -2.039222 3 0.484875 -0.840589 -1.006550 4 0.915714 0.631991 0.044289 5 -1.444943 -0.603629 0.552810 6 -0.113523 0.242165 1.309373 7 -0.676176 2.827214 0.223679 8 -0.467043 0.324336 -0.704214 9 0.329897 -0.121696 1.810813 In [153]: df[['A','B']].apply(sum) Out[153]: A -1.768975 B 2.210902 dtype: float64 In [154]: df[['A','B']].apply(lambda x: x.sum()) Out[154]: A -1.768975 B 2.210902 dtype: float64 2nd part, row-wise apply, returning 'sum' of elements in A and B columns. You can pretty much what what you want in apply. In [21]: df = DataFr

Categories : Python

Apply CSS To Particular Files
Sounds like you need a more specific selector. Do the popups have a unique class (or can you add one?), eg class="myPopup"? in that case, your css would be: <style> .myPopup {font-size:1.3em;} </style>

Categories : CSS

R apply odd behaviour with NA
The correlation matrix: corr_matrix <- as.matrix(read.table(text = "B1 B2 B3 A1 NA NA NA A2 0.3986434 NA 0.2807630 A3 -0.3568664 NA 0.6037172 A4 0.1974342 NA 0.6827092", header = TRUE, row.names = 1)) You can define a function to treat the cases where all values are NA: temp <- apply(corr_matrix,1, function(x) if (all(is.na(x))) NA else which.max(x)) temp # A1 A2 A3 A4 # NA 1 3 3 names(B)[temp] # [1] NA "B1" "B3" "B3"

Categories : R

how to apply css on specific td on first tr
Or if you don't want to put id's or classes you can do something like this: table tr:first-child td:last-child {} Note that not all browsers support the child selectors

Categories : Javascript

Using apply to get a numeric value
Your maths is off. DF <- data.frame(col1=c(1,2,3,0,7), col2=c(4,5,6,7,3)) result <- apply(DF,2,function(x) sum(x<5)/(sum(x!=5))) result #col1 col2 # 0.8 0.5

Categories : R

How do I apply CSS to part of the c:out value
public class StringParts { private String part1; private String part2; // constructor, getters } ... <span class="part1"><c:out value="${stringParts.part1}"/></span> : <span class="part2"><c:out value="${stringParts.part2}"/></span>

Categories : Jsp

using apply unapply
So apply and unapply are just defs that have extra syntax support. Apply takes arguments and by convention will return a value related to the object's name. If we take Scala's case classes as "correct" usage then the object Foo's apply will construct a Foo instance without needing to add "new". You are free of course to make apply do whatever you wish (key to value in Map, set contains value in Set, and indexing in Seq come to mind). Unapply, if returning an Option or Boolean can be used in match{} and pattern matching. Like apply it's just a def so can do whatever you dream up but the common usage is to extract value(s) from instances of the object's companion class. From the libraries I've worked with serialization/deserialization defs tend to get named explicitly. E.g., write/rea

Categories : Scala



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.