scope

How to iterate through angular $scope variables with a loop

大城市里の小女人 提交于 2019-12-18 11:47:09
问题 I want to iterate through $scope variables with a for loop like this. In this example the $scope object includes an object accounts inlcuding 5 objects, whose names are numbers from 1 to 5. Each of them has a name. for(var i = 1; i < 5; i++){ $('#name').val($scope.accounts.i.name); } The problem: $scope.accounts.i is undefined because i does not count as a varibale inside the $scope variable. It counts as the letter i, so I see no chance to iterate through a scope with a for loop. When I use

Declaring an object before initializing it in c++

佐手、 提交于 2019-12-18 10:59:28
问题 Is it possible to declare a variable in c++ without instantiating it? I want to do something like this: Animal a; if( happyDay() ) a( "puppies" ); //constructor call else a( "toads" ); Basially, I just want to declare a outside of the conditional so it gets the right scope. Is there any way to do this without using pointers and allocating a on the heap? Maybe something clever with references? 回答1: You can't do this directly in C++ since the object is constructed when you define it with the

Angularjs watch for change in parent scope

不问归期 提交于 2019-12-18 10:44:42
问题 I'm writing a directive and I need to watch the parent scope for a change. Not sure if I'm doing this the preferred way, but its not working with the following code: scope.$watch(scope.$parent.data.overlaytype,function() { console.log("Change Detected..."); }) This it logged on window load, but never again, even when overlaytype is changed. How can I watch overlaytype for a change? Edit: here is the entire Directive. Not entirely sure why I'm getting a child scope /* Center overlays

How to live with Emacs Lisp dynamic scoping?

我怕爱的太早我们不能终老 提交于 2019-12-18 10:03:57
问题 I've learned Clojure previously and really like the language. I also love Emacs and have hacked some simple stuff with Emacs Lisp. There is one thing which prevents me mentally from doing anything more substantial with Elisp though. It's the concept of dynamic scoping. I'm just scared of it since it's so alien to me and smells like semi-global variables. So with variable declarations I don't know which things are safe to do and which are dangerous. From what I've understood, variables set

scope variable undefined outside `.then` method

末鹿安然 提交于 2019-12-18 09:49:18
问题 I changed the scope variable in an if statement and outside the if statement it turned into an undefined variable app.controller("Login", function($scope, $window,$http){ var status; $scope.loginUser = function(logData){ $http.post('/corporate/login',logData).then(function(response){ var data = response.data var status = data.success; if(status == true){ $scope.logStatus = true; console.log($scope.logStatus); // prints true }else{ $scope.logStatus = false; } }) console.log($scope.logStatus);

How to avoid setting variable in a try statement

余生长醉 提交于 2019-12-18 09:49:07
问题 My problem is that I have to set a variable in a try statement otherwise I get a compile error. Later on I need to use that variable but it is now out of scope, or so I believe. I initialise the variable outside the try statement and set it to null, I thought that it might then be accessible outside, but I still get a NullPointerException . The code is below, with lots of it taken out to make reading easier - I know it's bad code, but I am new to Servlets and just wanted to see it running

Javascript: always execute function in execution context

自古美人都是妖i 提交于 2019-12-18 09:45:55
问题 I wrote this fast-templating function: var templatize = function(string) { return function (string) { return string.replace(/{{(.*?)}}/g, function(pattern, match) { value = this[match]; if (value) { return value; } else { return pattern; } }); }.call(this, string); } Which does this: var foo = "bar", bar = "foo"; templatize("We are {{foo}} and {{bar}}, but not {{crazy}}"); // "We are bar and foo but not {{crazy}}" I'm quite happy with this except that I have scoping problem. For sure, the

JQuery: Return $.get() callback to outer scope

断了今生、忘了曾经 提交于 2019-12-18 09:44:58
问题 I'm working on this validation script for my latest project, and one of the requirements is that it checks if the value that the user enters is in the database, and if it isn't it returns an error. function validateSteps(){ var FormErrors = false; for(var i = 1; i < fieldsetCount; ++i){ var error = validateStep(i); if(error == -1) FormErrors = true; } $('#formElem').data('errors',FormErrors); } function validateStep(step){ if(step == fieldsetCount) return; var error = 1; var hasError = false;

JSF - Problem with @ViewScope

久未见 提交于 2019-12-18 09:37:34
问题 I have a page that load (in a panelGroup) two different page, due to the login status (logged, not logged). This is the main switch : template.xhtml P.S. selector.page is "homepage" as default <h:panelGroup layout="block" styleClass="contenitore"> <h:panelGroup layout="block"> <h:panelGroup layout="block" styleClass="menu_table" id="login"> <ui:insert name="login_homepage" /> </h:panelGroup> <h:panelGroup layout="block" id="content"> <c:catch> <ui:include src="/#{selector.page}/#{selector

AngularJS: code not working when iterating through object [duplicate]

自作多情 提交于 2019-12-18 09:33:49
问题 This question already has answers here : 'this' vs $scope in AngularJS controllers (7 answers) Closed 3 years ago . I am trying to populate a list of employee objects from my controller empctrl in a template. Here's the controller: app.controller('employeeController', function ($scope, employeeService) { this.employees = {}; this.populateTable = function (data) { this.employees = data; }; var error = function (err) { console.log("Error: " + err); }; // Call Service to List all Employees