w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Which is faster: using a global, pass by value, using a pointer?
It depends very much on the machine, the type of the variable, how you use it inside the function and outside it, whether it is const or volatile, the compiler, the flags you pass to the compiler, etc. You can't optimize without a program to optimize and a system to optimize it for. (Disclaimer: I don't have real-world expertise on the matter)

Categories : C

Global "App" controllers in AngularJS
Purely in context of situation. Let's take an example of dynamically changing title tags and page view: .config(['$routeProvider','$locationProvider',function($routeProvider,$locationProvider){ $routeProvider.when('/', { template: '/views/home.html', title:'Home' }); $locationProvider.html5Mode(true); }]); .controller('app', ['$scope','$route','$location',function($scope,$route,$location){ $scope.$on("$routeChangeSuccess",function($currentRoute,$previousRoute ){ $scope.title = $route.current.title; $scope.page = $route.current.template; }); }]); Now both our title and page view are being dynamically loaded in through app level controller that wraps our application. This can be very useful. <html lang="en" ng-controller="app"> <head> <title>{{

Categories : Javascript

How to pass global variable in javascript function
$_SESSION is an array and this will return blank if you echo it. You should use the <?php echo $_SESSION['password']; ?> It will echo the password that store in Session.

Categories : PHP

AngularJS - $filter not in global scope
You can use $filter('date') to get the date filter by injecting the $filter module before the actually test stub. I created a working demo for you and please take a look at the required JS files. describe('date', function () { var dataFilter; beforeEach(angular.mock.module('Customer')); beforeEach(function () { angular.mock.inject(function ($filter) { dataFilter = $filter('date'); }) }); describe('date result', function () { it('should return filtered date', function () { var date = new Date(2013, 7, 15); expect(dataFilter(date)).toBe('08/15/2013'); }); }); }); Demo

Categories : Angularjs

trying to pass the current radiobutton value in tkinter but getting global name not defined
Indent your code correctly. from tkinter import * import random class App: def __init__(self, master): self.say_one() def say_one(self): v = IntVar() window = Toplevel(root) for i in range(1,11): self.label = Radiobutton( window, text = i , fg = "red", value = i, variable = v ).grid(row =i, column =0) # error is occurring in the next line self.report = Button( window, text="submit", command=lambda: num(v) ).grid(row = 12, column = 0) def num(var): print(var.get()) root = Tk() app = App(root) root.mainloop() I fixed the indentation, changed the num function to print variable's value instead of printing variable itself.

Categories : Python

How to pass global variable in javascript callback functions?
You have a name conflict between the function parameter and the global variable. As the function parameter name is closer to the executed code, when JavaScript looks up through the variable names to find out what you meant, it finds the parameter name first, so that is what becomes set. If you want to explicitly set the global variable, you'll have to access it though window, i.e. window.year = true; // explicit global

Categories : Javascript

pass a global variable from appdelegate returning null
Try adding an NSLog(@"sn: %@", sn); after your log of sn1. It's likely that, after you set sn = input;, when that method is complete, input goes out of scope. This make sn an invalid pointer, and you pass LTField.text a null reference. Usually, when you want to keep an NSString object passed as an argument, you would use: sn = [input copy]; You want to copy the input variable since NSString is immutable, similar to how you would retain a mutable object. Also, you should change your @property declarations to (nonatomic, copy) for the NSString's, and then you could use self.sn = input; if you prefer (since using self and dot notation calls the setter instead of directly using the variable). See this question for some extra information: NSString property: copy or retain?

Categories : IOS

Python - pass members of global variable to function, still make changes
You have to realize that the job in other_function has nothing to do with USERS except the value of it equals USERS[0].job[0]. So whatever you do on it, the USERS won't change. It has nothing to do with global. So change your code to: def main(): global USERS jobs = ["Mow", "Rake", "Mulch"] USERS = [User("Fred", jobs), User("Mark", jobs), User("Greg", jobs)] USERS[0].jobs[0] = other_function(USERS[0].jobs[0]) save(USERS) def other_function(job): job = 'Nothing' #do something on the value return job

Categories : Python

How can I define a global $httpBackend for servicesSpec and controllersSpec in AngularJS?
I imagine your code looks like this: angular.module('MyApp', []) .controller('MyCtrl', function($scope, MyService) { $scope.doSomething = function() { MyService.doSomething(); }; }) .service('MyService', function($http) { $http.get('some-url') .success(function(response) { // Handles the response }); }); In order to unit test MyCtrl you need to mock out its dependencies: $scope and MyService. So in your test you can do this: describe('MyCtrl', function() { var MyServiceMock, scope; beforeEach(function() { module('MyApp'); // Creates a mock (spy) for MyService MyServiceMock = jasmine.createSpyObj('MyService', ['doSomething']); inject(function($p

Categories : Testing

How do I trigger a angularjs page refresh in a global callback function?
If you want to get your angular scope updated after the global callback was triggered you have to manually update your scope. // If you do have access to your scope via $scope $scope.$digest(); // If you don't have access to the scope var element = document.getElementById('dashboard'); // Get the scope for your element where your controller is bound to var scope = angular.element(element).scope(); scope.$digest();

Categories : Javascript

Android/Java - How pass a global variable value from main activity to a runnable class
You can use asynctaks (background proccess ): http://developer.android.com/reference/android/os/AsyncTask.html

Categories : Java

angularjs pass select option
ngModel holds the value of the selected option. So remove the value attribute from the select tag. Assuming the model to be as below $scope.lines = [ { name:"1" }, { name:"2" }, { name:"3" } ]; You can change the ng-options to below to specify the values as well: <select ng-model="record.Line" ng-options="l.name as l.name for l in lines" />

Categories : Javascript

Variable won't pass over as an argument in AngularJS
Try removing the {{}} in your function call. They aren't required. Not sure why it would still find some of the vars and not others, but in my plunker when I removed them, things started working.

Categories : Forms

Angularjs how to pass in data using a directive
Try something like this: .directive('getWidth', function(){ return{ controller: 'QuotesCtrl', link: function(scope){ console.log(scope.theRowHeight); }, scope: { 'theRowHeight': '=' } } }); Markup: <div the-row-height="20"></div>

Categories : Javascript

AngularJS - pass callback from view?
In angular, the preferred way of doing DOM manipulation is to use directives... or to bind your view logic with directives like ng-show or ng-hide Just create a directive to wrap your modal window with, or use angular ui bootstrap's $dialog service.. which is an excellent one.

Categories : Jquery

How to pass object between directives AngularJS?
Quote from documenation: The controller is instantiated before the pre-linking phase and it is shared with other directives (see require attribute). This allows the directives to communicate with each other and augment each other's behavior. This means that to share data between two directives on the same object or it's children, you'll need to expose foo inside directive A controller, injected with require option in directive B. The directives would look like this: .directive("dirA", function () { return { controller: function ($scope, $element, $attrs) { }, link: function ($scope, $element, $attrs, controller) { controller.foo = $attrs.dirA; } } }) .directive("dirB", function () { return { link: function ($sco

Categories : Javascript

AngularJS pass requestVerificationToken to a service
sadly, the easiest way is to include jquery.js into your project before angular.js, then do this: headers: { 'X-XSRF-Token': angular.element('input[name="__RequestVerificationToken"]') }

Categories : Angularjs

AngularJS: How can I pass in the ID to a show action?
App.controller 'LeaderboardsCtrl', ['$scope', 'Leaderboard', ($scope, Leaderboard) -> $scope.selectedLeaderboard = Leaderboard.query({id: 'count-receiver'}) ] Just have to pass the ID to the service as above.

Categories : Ruby On Rails

Storing nodejs fs.readfile's result in a variable and pass to global variable
The problem you have isn't a problem of scope but of order of operations. As readFile is asynchronous, console.log(global_data); occurs before the reading, and before the global_data = data; line is executed. The right way is this : fs.readFile("example.txt", "UTF8", function(err, data) { if (err) { throw err }; global_data = data; console.log(global_data); }); In a simple program (usually not a web server), you might also want to use the synchronous operation readFileSync but it's generally preferable not to stop the execution. Using readFileSync, you would do var global_data = fs.readFileSync("example.txt").toString();

Categories : Javascript

AngularJS - Pass object data into modal
It helps to know which $dialog service you are referring to exactly, since $dialog is not the part of core AngularJS API. Assuming that you are using the $dialog service from the ui-bootstrap, you can pass your user object into the dialog controller through the resolve property of $dialog configuration object. As the $dialog documentation states it: resolve: members that will be resolved and passed to the controller as locals function DepCtrl($scope, Dependents, $dialog) { $scope.data = Dependents; $scope.opts = { backdrop: true, keyboard: true, dialogFade: true, backdropClick: false, template: t, // OR: templateUrl: 'path/to/view.html', controller: 'TestDialogController', resolve: { user: function(){ return $scope.data; }

Categories : Javascript

Angularjs $resource - cannot pass array as one of the parameters
I created a plunkr for this one here. You are right, the resource service won't do what you want it to do.. at least I couldn't get it to. The way I was able to get it to work was by leveraging the $http service and building up my querystring with comma delimited values attached to the param 'status'. The result is a URI in the form: http://run.plnkr.co/someUrl?status=One,Two,Three On your API side, you can interpret the comma delimited arguments as elements with indexes. The basic build up in the code is something like this: var statusValues = ["One", "Two", "Three"]; var queryParams = "status="; for (var i=0;i<statusValues.length;i++){ queryParams += statusValues[i]; if (i != statusValues.length-1){ queryParams += ","; } } $http.get('/someUrl?' + queryParams).success(s

Categories : Angularjs

how to pass an object to a directive template in angularjs?
The problem is that you add opts property to scope in the post-linking function, which will be called after modal directive's linking function, so the modal directive will never get those options. The solution is to move scope.opts = ... to pre-linking function: directive('update', function() { return { ... compile: function() { return { pre: function(scope, elm, attr){ ... scope.opts = { backdropFade: true, dialogFade: true }; } }; } } } http://plnkr.co/edit/iZaEiM?p=preview

Categories : Angularjs

How can I pass params with AngularJS $resource.query?
Below is the sample code: angular.module('phonecatServices', ['ngResource']). factory('Phone', function($resource){ return $resource('phones/:phoneId.json', {}, { query: {method:'GET', params:{phoneId:'phones'}, isArray:true} }); });

Categories : Javascript

How to pass ampersand (&) to AngularJS resource parameter
So, I hate giving this kind of answer because I haven't actually done this myself, but have you looked into angular's http request interceptors? http://docs.angularjs.org/api/ng.$http

Categories : Javascript

AngularJS - Pass variable from a controller & update from directive
Shortly: bind to objects instead text values. Longer: see your forked Plnkr http://plnkr.co/edit/wzfwQI See comments which starts from "Changes:" in script.js and dynamicTextFields-template.html

Categories : Angularjs

angularjs - pass selected object's other properties on ng-change
Instead of passing in a property, you can pass the selected object into the function like this <select ng-model="campaign" ng-options="c.name for c in campaigns" ng-change="search2(campaign)"> Working Demo

Categories : Angularjs

How can I pass multiple parameters separated with a ? and & using AngularJS $resource?
Just add query parameters to the object parameter, i.e.: getEntity: function (entityType, entityId) { var deferred = $q.defer(); EntityResource.getEntity({ entityType: entityType, entityId: entityId, subjectId:12, contentTypeId:23 }, function (resp) { deferred.resolve(resp); } ); return deferred.promise; } Look at the parameters section in the AngularJS documentation for an explanation.

Categories : Angularjs

AngularJS: How to pass values from Controller to Service Method?
One way of doing it is to inject the service into your controller: angular.controller('controllerName', ['$scope', 'Transaction', function($scope, transactionService) { ... } ]); Then you can access an instance of your service through the transactionService parameter. EDIT check out this fiddle Tell me if this is close enough to what you are trying to do

Categories : Javascript

AngularJS pass model to controller in live update
Most definitely you can. Just define the function in the same controller. For instance Controller: app.controller('myCtrl', function($scope) { $scope.increment = function() { return $scope.myModel; } }); HTML <div data-ng-controller='myController'> <input data-ng-model='myModel'> <p>{{increment()}}</p> </div> That returns the exact same thing as {{myModel}}

Categories : Javascript

How to pass a JavaScript object already on the page in to an AngularJS template
You need to make a couple of changes. Normally ng-model is used on inputs, but in your case we can use it as a marker to link angular world with non-angular world. <div ng-app="plunker" ng-model="currentRecord" ng-show="currentRecord"> {{currentRecord.FirstName}} - {{currentRecord.Surname}} </div> ng-model only binds to a javascript object on the current scope, so if you need to access properties from it you need to reference it directly. Updating the model from an external(not angular) source function myExternalFunction() { //external code // we need to get the element and wrap it in an angular element var $element = angular.element('[ng-model="currentRecord"]'); var scope = $element.scope(); //the ngModel controller will have the correct apis va

Categories : Javascript

How to pass Rails current_user to AngularJS factory API call?
The user should never be sent from the client. You should never trust the client. Your rails app should have a session, and you should store the current user somewhere in the session. (Session is a hash, if you are doing it manually just use a sensible key to store the current user's ID). You do it on logging in, and just retrieve it afterwards. class ApplicationController < ActionController::Base attr_accessor :current_user before_filter :load_current_user # ... private def load_current_user self.current_user = User.find(session[:user_id]) end end And in your controller: def usersubmission @submissions = current_user.submissions @submission = @submissions.find(params[:id]) render json: @submission end If you use Devise or similar it's much easier an

Categories : Javascript

how to pass data from compile to linking function in angularjs?
I think it's enough considering the scope of JavaScript symbols. See this http://jsfiddle.net/JV7vH/1/ you define a compile function that has to return a link function. because it's an inner function, symbols from parent functions are visible. app.directive('ui',function ($compile) { return { restrict:'E', template: '<div class="mcb">hey</div>', compile: function ($tElement, $tAttrs) { var foo = "a valuable value"; console.log('compiling' + foo); return function (scope, element, attrs) { console.log('linking:' + foo); } } } }); you might also want to read about the order of execution of compile-link @joshdavidmiller said that given: <div directive1> <div directive2> <!-- ... --> &l

Categories : Angularjs

How to pass values from text area to table using AngularJS
Change ng_model = "letters" to ng-model = "letters". And letters should be an array instead of string. You have to split the input to list of strings. $scope.arrangelist = function() { var letterplits; letterplits = $('#letterlist').val().split(' '); $scope.letters = letterplits; return $('#arrangelist').modal('show'); }

Categories : Javascript

angularjs directive call function specified in attribute and pass an argument to it
Not knowing exactly what you want to do... but still here's a possible solution. Create a scope with a '&'-property in the local scope. It "provides a way to execute an expression in the context of the parent scope" (see the directive documentation for details). I also noticed that you used a shorthand linking function and shoved in object attributes in there. You can't do that. It is more clear (imho) to just return the directive-definition object. See my code below. Here's a code sample and a fiddle. <div ng-app="myApp"> <div ng-controller="myController"> <div my-method='theMethodToBeCalled'>Click me</div> </div> </div> <script> var app = angular.module('myApp',[]); app.directive("myMethod",function($parse) { var direc

Categories : Angularjs

Pass variables between functions vs global variables
I'd suggest that what you want is a data structure which is filled in by the various functions and then passed into make_plot at the end. This largely applies in whatever language you're using.

Categories : Python

AngularJS: loop POST requests and pass each index into related response
This will do the trick: var params = [1, 2, 3], url, i, done = {}; for (i in params) { (function(p) { url = '/dir/'+ params[p]; $http.post(url, {"some_request": "not important"}). success(function(response) { done[params[p]] = 'successful'; }); })(i); } Another option is closure.

Categories : Javascript

Safe to pass current $scope from controller to angularjs service function
I would not pass the scope. Instead, I would explicitly, in your controller, hook up the unsubscribe. From http://odetocode.com/blogs/scott/archive/2013/07/16/angularjs-listening-for-destroy.aspx : $scope.$on("$destroy", function() { if (timer) { $timeout.cancel(timer); } }); I think having this done explicitly is not as magical, and easier to follow the logic. I think the service would be doing too much if it were to also unsubscribe. What if a controller wants to unsubscribe early? However, if you do have a very specific use case that's used everywhere, it would be fine to pass the scope in. The amount of time the service needs the scope is very small, basically when the controller first executes so that the service can listen to the $destroy event.

Categories : Angularjs

Making sure global logger object lives longer than other global objects
Just use the classical singleton idiom. You don't want shared_ptr here, because you don't want to destruct the object, ever. Basically, something like: class LoggingProvider { static LoggingProvider* our_instance; public: static LoggingProvider& instance(); // ... }; LoggingProvider* LoggingProvider::our_instance = &LoggingProvider::instance(); LoggingProvider& LoggingProvider::instance() { if ( our_instance == NULL ) { our_instance = new LoggingProvider; } return *our_instance; } The important things here are 1) the pointer has no non-trivial constructor, and 2) the instance is never destructed. One thing: since any file you're outputting to will never be closed, make sure you flush all output. (I usually do this by using shor

Categories : C++

Updating a Global Variable on Page Load VB.net in Global.asax
You can use inheritance. Create a class (BasePage) and every page can inherit this base page. In the Page_Load (or Pre_Init) of the base page, put your DB check. This will allow you to check on some pages, but not all (if that is ever necessary).

Categories : Asp Net

$_GET global scope in function as not global?
Because $_GET is a superglobal, you can't change it wthout affecting it globally. But why not simply take a local copy to "use" inside your function: function url($toSort) { $localGet = $_GET; $localGet['sortby'] = $toSort; echo http_build_query($localGet); }

Categories : PHP



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