w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Resource based routing module used in a Node.js REST API service, or other useful modules for this type of service
RESTfull API get and post data through HTTP protocol. A more progressive approach is to use WebSocket [Wikipedia] npm link. Try to play with Sails.js framework build on Express.js that use Socket.IO for flash data transfering

Categories : Javascript

AngularJS - Shared state between controllers?
Short answer Create a service, see Creating Services for details. Long answer Services are - per se - application-wide singletons, hence they are perfect for keeping state across views, controllers & co.: app.factory('myService', [ function () { 'use strict'; return { // Your service implementation goes here ... }; }]); Once you have written and registered your service, you can require it in your controllers using AngularJS' dependency injection feature: app.controller('myController', [ 'myService', '$scope', function (myService, $scope) { 'use strict'; // Your controller implementation goes here ... }]); Now, inside your controller you have the myService variable which contains the single instance of the service. There you can have a property isLoggedIn that r

Categories : Angularjs

Issues binding / watching service variable shared between two controllers
I don't really know why, but it seems to be corrected if you use a function to return the data in your service, and then you watch that function instead of the property. As it seems unclear, you can see it here : http://jsfiddle.net/DotDotDot/Mujun/10/ I added a getter in your service : var service = { things: [], setThings: function (newThings) { service.things = newThings; }, getThings:function(){ return service.things; } }; then, I modified your code in both controller by this : $scope.things = TestService.getThings(); $scope.getThings=function(){return TestService.getThings();}; $scope.$watch('getThings()', function (n, o) { if (n !== o) { // never alerts alert('Thi

Categories : Javascript

angularjs: using service to communicate between controllers
angular.module('myservices', []).factory('serviceA', function () { return { //// factory returns an object var serviceA= { selectedItem: selectedItem, ... more functions here }; return serviceA; var selectedItem; ... functions go here } }); does this work? you were missing the return{} part,where everything goes there. if you would use service you would write just this.serviceA={...} and your code in controller is missing $scope ! $scope.someItem= serviceA.selectedItem; or (i dont really know what you want) $scope.serviceA.selectedItem= someItem; then in your span <span>{{someItem.value}}</span> or (i dont really know what you want) <span>{{serviceA.selectedItem.value}}</span> PS i dont like that

Categories : Angularjs

AngularJS Service Passing Data Between Controllers
Define your service like this app.service('userService', function() { this.userData = {yearSetCount: 0}; this.user = function() { return this.userData; }; this.setEmail = function(email) { this.userData.email = email; }; this.getEmail = function() { return this.userData.email; }; this.setSetCount = function(setCount) { this.userData.yearSetCount = setCount; }; this.getSetCount = function() { return this.userData.yearSetCount; }; }); Check out Duncan's answer here: AngularJS - what are the major differences in the different ways to declare a service in angular?

Categories : Angularjs

AngularJS share asynchronous service data between controllers
Something like this: $http.get(globals.serverUrl + api_path + id).then(function(result){ sharedService.frames = result.data; }); If you want your getAsync method to return the data when the call has completed then you can use defer: sharedService.getAsync = function (id) { sharedService.frames = {}; var defer = $q.defer(); $http.get(globals.serverUrl + api_path + id). then(function(result){ sharedService.frames = result.data; defer.resolve(result.data); }).error(function (data, status, headers, config) { console.log('HTTP error'); }); return defer.promise; };

Categories : Angularjs

how to use factory/service for sharing information between multiple controllers in angularjs?
You can access to $scope with : angular.element(document.getElementById('YourCtrl')).scope(); After, you can init data in all your controllers.

Categories : Http

Model of a shared service isn't updating in AngularJS
The problem was that I was using $scope instead of $rootScope, the data gets updated through the first controller in the service but there's nothing that informs the second controller of this change: code in the first controller that notifies $rootScope of a change $scope.setLang = function(locale){ $rootScope.data = sharedService.getData(locale); }; code in the second controller watching for change $rootScope.$watch('data', function(newValue) { $scope.data = newValue; }); below is a link to the 'wrong' fiddle and one that works for when somebody else also has this problem: wrong one: http://jsfiddle.net/GFVYC/1/ working one: http://jsfiddle.net/GFVYC/4/

Categories : Javascript

AngularJS Binding, multiple controllers through a service, part of page rendered from php
There are a couple ways you can handle this. You can bind your $scope to the service itself, in which case any changes to that model will be picked up automatically You can observe changes to the service using $watch In this example, you can see both techniques: (http://plnkr.co/edit/bhBXMr?p=preview): var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope, AuthenticationService, UserService) { $scope.user = UserService; $scope.login = function(){ AuthenticationService.login(); } // watch the service for changes to currentUser $scope.$watch(function(){ return UserService.currentUser; }, function(currentUser){ $scope.currentUser = currentUser; }, true); }); app.service('AuthenticationService', function($http, UserService){ retu

Categories : Database

Angularjs - Accessing shared service data from an ng-repeated directive
First and foremost, your binding are evaluated in context of $scope variable. You cannot have a service and direct bind to its data. So actually you need a wrapping element. So either you use div or any parent of the repeat element. I have updated you jsbin see here. You can still do it without the service, by using the controller.

Categories : Javascript

AngularJS: display a select box from JSON data retrieved by http GET (from REST service)
It is because Angular does not know about your changes yet. Because Angular allow any value to be used as a binding target. Then at the end of any JavaScript code turn, check to see if the value has changed. You need to use $apply var ListOptionsCtrl = function ListOptionsCtrl($scope, $http) { $scope.refreshList = function() { $http({ method: 'GET' url: '*someurl*' }). success(function(data) { $scope.$apply(function () { $scope.optionsList = angular.fromJson(data); }); }); }; } Try this. More about how it works and why it is needed at Jim Hoskins's post

Categories : Javascript

Configuring AngularJS modules - how does it affect the other modules in the app?
Here is what i think. Like any other angular $httpProvider is also singleton in nature which very well means any changes to it from any where including any module would affect other, or in other words changes are global.

Categories : Angularjs

Pattern to get rid of imports in modules as in web2py controllers
The web2py framework does a lot of behind the scenes work to make all that stuff available. For example, when you go to a URL like host/app/controller, that controller is called by web2py (starting with something in web2py.py) that handles importing web2py modules, providing request/response objects, etc. Things placed in modules, however, are intended to be standalone Python code, not necessarily specific to web2py.

Categories : Python

AngularJS Client, JAX-RS Jersey Rest Service - application/json client request throwing 'Error parsing media type'
Your Content-Type header is invalid (see spec 14.17 Content-Type). Based on you JAX-RS resource you should use application/json as Content-Type (without application/x-www-form-urlencoded): $http({ method: 'POST', data: $scope.Patient, url:'/ManagePatient/AddPatient', headers: {'Content-Type':'application/json'} }); EDIT 1: If you want to see requests that are coming to your server you can register LoggingFilter and it will show you some useful information. You can turn it on in: web.xml (add it to the JAX-RS servlet definition): <init-param> <param-name>jersey.config.server.provider.classnames</param-name> <param-value>org.glassfish.jersey.filter.LoggingFilter</param-value> </init-param> Application extension: public class MyAppl

Categories : Angularjs

Shared Values for multiple modules in Drupal 7
Probably, you are looking for variable_set & variable_get drupal apis. Example: Set the value like this: variable_set('email_id', 'abc@xyz.com'); Then you can retrieve it in any module like following: $email_id = variable_get('email_id');

Categories : Drupal

What is the proper way to work with shared modules in Python development?
I think that this is the best reference for creating a distributable python package: http://guide.python-distribute.org/creation.html also, don't feel that you need to nest everything under a single directory. You can do things like platform/ core/ coremodule api/ apimodule and then do things like from platform.core import coremodule, etc.

Categories : Python

How to package shared objects that python modules depend on?
Declaring dependencies There is an option in setup.py called install_requires = [""] : Ex : setup( name='django-cherrypy', version='0.1', packages=packages, license='LICENSE', description='cherrypy, running under django', long_description=open('README.md').read(), author='Calvin Cheng', author_email='calvin@calvinx.com', install_requires=['cherrypy-wsgiserver'], extra_requires=['newrelic'], url='https://github.com/od-eon/django-cherrypy', ) This setup ask for chrerryPy WSGI server library. Bundle Everything Everything is explained here : http://pythonhosted.org/distribute/setuptools.html#declaring-dependencies Depedencies in PiPy : When your project is installed, either by using EasyInstall, setup.py install, or setup.py de

Categories : C++

phalcon include modules in rest
Obviously all is possible ! If you want to keep your structure with application+micro I think the best way is to create 3 configs. A first config that is common with both of api and www A second one which is loaded only by your www with its one router A thirds one which is loaded only by your api with its one microrouter and which redefines the different paths to the rest module. If you want just to use a multi module application with a single config file, then I can advice you to use the domain recognition in your router thanks to the setHostName() method. Then in your config file you define an api hostname and a www hostname that you use everytime. You may also put them in global constant for more convenience. // an api get route $router->add("/getsomething",...) ->v

Categories : Rest

Struts2 - Rest Controllers ModelDriven with different model types
There's not a better way to do it; what else would you do? I suppose you could create a model-specific Pair or a single/list composite and use the appropriate value/field in your results, but I'm not really sure you gain much by doing so.

Categories : Java

Getting human-readable stack trace when testing REST API modules
Resolved. Actually, it was logical : If you change the "Accept:" request header (example -H "Accept: application/json" in Curl) the trace will be returned as Json by the server if an error occurs.

Categories : Rest

How to optimize the performance for Azure Service Bus REST Service
1) If your clients are using ChannelFactory, then cache the channels. 2) Is your endpoint on a data center near you and your customers? If not, I would highly suggest you change that. 3) According to the docs, if you are using NetTcpRelayBinding you can also set the TcpConnectionMode to Hybrid, which will establish "direct connections between two parties that sit behind opposing Firewalls and NAT devices"

Categories : Azure

How to convert SOAP web service to REST web service in Mule
I guess Mule ESB should be best in doing this. Step 1 : You can expose a rest service via http endpoint which should accept your JSON. Step 2: Then a Custom Transformer can be used to prepare the SOAP request for the SOAP service which needs to be called. Step 3: OutBound Call to SOAP Web-Service Step 4: Transformer to convert your SOAP Response from previous out-bound call to JSON response. The response will be sent back to the client which calle dthe Rest Endpoint. Hope this helps :)

Categories : Rest

How to host a SOAP service and REST service at the same port?
If you are using a common container such as tomcat for your webservices, then you can get requests for both of the services arriving on the same port. You can deploy both the REST and SOAP based services as part of your application. The container will accept the incoming request and will forward them to the application depending on the application context. In your application web.xml, you can configure the where to send the request depending on the request URL mapping.

Categories : Java

Should REST be used in a service that only has Service Operation Calls?
Saved this awhile back, its a source from some article I read, hopefully it can help you: REST and traditional SOA applications both must specify if they are trying to create, update, retrieve, or delete something during a method call. How do they differ? Since REST URLs look like, http://here/an/example then how does the service know if you’re retrieving the record or deleting it? In REST, if you’re, say, trying to delete something, you use the HTTP DELETE method, which is buried in the HTTP header and not visible in the URL itself. If you’re trying to retrieve something, you use the HTTP GET method. This is different than how traditional SOAP web services do it. With SOAP-based web services, the HTTP method is always set to “POST” regardless if you

Categories : Wcf

Controllers granularity in AngularJs
Basically you're checking the $routeParam to see if there is a detail to look for, if not, looking for the list. http://plnkr.co/edit/jAK31F?p=preview

Categories : Angularjs

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

AngularJS controllers created with "new" or not
The "as" syntax is only an alias and the documentation is correct that Angular never creates instances of the controller type by invoking the new operator on the controller constructor. The new behavior with aliasing is such that now $ControllerProvider does a regexp test for the presence of the as keyword and, if present, stores a reference to the controller on the local scope under the alias name. Here is a link to the git feature commit that changed the relevant code. Also: From the Angular source (1.1.5), here is the code in $ControllerProvider that creates the controller: instance = $injector.instantiate(expression, locals); and here is the instantiate method: function instantiate(Type, locals) { var Constructor = function() {}, instance, returnedValue; // Check if

Categories : Javascript

sharing between modules with AngularJS?
Inject a module into both that shares these properties. Use the provider class to overwrite properties or instantiate them from any scope: angular.module("stuff.things", []).provider("$things", function(){ var globalOptions = {}; this.options = function(value){ globalOptions = value; }; this.$get = [, function () { function Things(opts) { var self = this, options = this.options = angular.extend({}, globalOptions, opts); } Things.prototype.returnOptions = function(){ return this.options; }; return { things: function(opts){ return new Things(opts); } }; }]; }); The secret sauce: $things.things().returnOptions() angular.module('stuff.thing1', ['stuf

Categories : Javascript

How to use two AngularJS services with same name from different modules?
The service locator looks services up by name (angularjs guide DI). However "Namespacing" services in AngularJS: As of today AngularJS doesn't handle namespace collisions for services so if you've got 2 different modules with the service named the same way and you include both modules in your app, only one service will be available. I guess you can make the fully qualified name "by hand": name the service foo.baz and bar.baz instead of plain baz. It's kind of a self-delusion. Moreover, writing it this way doesn't make namespacing real, but another person that reads the code might think so.

Categories : Angularjs

Broadcasting across AngularJS controllers?
It depends on the scopes hierarchy and therefore on where you bootstrap your Ctrl1 and Ctrl2 in your dom. Say Ctrl1 is the parent of Ctrl2. $broadcast will transmit the event to child scopes: Ctrl2 in this case will notice it (use $on). If you need to transmit an event from Ctrl2 to Ctrl1, use $emit that transmit the event to parent scopes.

Categories : Javascript

If i am having the 5 pages with 5 controllers in angularjs
All Angular services are application singletons. This means, you can change state of the service once, and the change will be 'visible' to all it's users. The service gets instantiated when application will ask for it. While the service exists, all the controllers, etc. will receive a reference to the same service instance (I would still expect the service to be garbage collected when all the references to the service are lost). This means, after you initialize the service, all controllers can invoke methods, etc. - all on the same instance, visible to all other instances. Here's a jsFiddle showing the concept. When the value in factory object is changed in one controller, it is visible throughout the application. Both controllers use the modified value of testFactory.name, as it gets m

Categories : Angularjs

Communication between modules in AngularJS
You can use services and controllers inheritance (explained here http://docs.angularjs.org/guide/dev_guide.mvc.understanding_controller) in any case, you shuold consider not having your controllers tighlty coupled.

Categories : Angularjs

AngularJS .bootstrap() and Modules
The ng-app directive bootstraps your application. If you want to bootstrap it manually, you should not use ng-app. angular.bootstrap also takes the root module to bootstrap; in this case, this is your myAppModule module (which already depends on ui.map because of the angular.module definition). Thus, your code would look more like the following: function onGoogleReady() { console.log("GMaps api initialized."); var body = document.getElementsByTagName('body')[0]; angular.bootstrap(body, ['myAppModule']) }

Categories : Angularjs

Declaring controllers in AngularJS
You should follow the second example they offer, which uses a string to identify your controller rather than a potentially global function. Use the Array syntax so you can minify your code without worrying about the minifier renaming function parameters. var myApp = angular.module('myApp'); myApp.controller('GreetingCtrl', ['$scope', function($scope) { $scope.greeting = 'Hola!'; }]); Source: http://docs.angularjs.org/guide/controller

Categories : Javascript

Passing service between controllers and directives
Here is my best guess, why binding is not working. Initially you are setting the array to mySource = []; Later you replace the reference when the data comes from the server. mySource = success.data; Instead can you try mySource.push method to update data in the intial array. Also just wanted to point out that the first $watch expression should take the first parameter as variable name string rather than the variable itself.

Categories : Javascript

Controllers not talking to each other via service in Angular JS
I just remembered I already answered this here: How to share data between controllers in angularjs var app = angular.module('myApp', []); app.factory('myService', function() { var myService = { foo: 'bar' }; return myService; }); app.controller('myCtrl1', function(myService) { console.log(myService.foo); myService.foo = 'not bar anymore!'; }); app.controller('myCtrl2', function(myService) { console.log(myService.foo); }); The only thing you need to do is then set your $scope.cartModel = cartModel and then you could do things like ng-model="cartModel.someProp" and any change there is updating that property in your service and thus updating it to any $scope.cartModel that is referencing the service object.

Categories : Angularjs

Angular service not passing between controllers
The problem is your TableRowCtrl saves the result of a function in its scope variable. When the service itself changes, the value in the scope does not because at that point, it's a simple property. You can either expose your service directly in the scope or wrap $scope.items in a function instead: function TableRowCtrl($scope, $http, sharedProperties) { $scope.items = function() { return sharedProperties.getProperty(); }; } // And in your view {{ items() }} Or function TableRowCtrl($scope, $http, sharedProperties) { $scope.shared = sharedProperties; } // And in your view {{ shared.getProperties() }} Edit: Simple plunkr here Edit #2: If the problem is a binding that isn't updated because of an asynchronous process, you can use $scope.$apply: $http.get('data/customers.js

Categories : Javascript

AngularJS loading controllers from folder
You can put the your code where you wants to. If you put them into angular modules, angular will find it. So if you have a service in /app/common/services/foo.js like: angular.module('app').service('foo', function() { ... }); You can do this in the userController: angular.module('app').controller('UserController', function($scope, foo) { ... }); Here you see how I injected foo in our controller. Angular Dependency Injection system is smart enough to find your code no matter where you put them. You can also create different modules than app, you can have: angular.module('other').service('bar', function() { ... }); And where you define the app module, something like this: angular.module('app', []); You just need to add the new module there as a dependency, that is what the [] ar

Categories : Javascript

When to use nested controllers instead of services in angularjs?
This is 100% judgement call, and should be based on a couple of points. Using events creates extremely loosely coupled components, they literally do not need to be aware of one another, if you have a situation where some parent controller would alleviate the need to communicate between a bunch of controllers (via services) then it is probably a better solution. However if you're okay with the controllers each depending on the service (not really a problem) then you could just use the service as a means of communicating changes between the controllers. I've seen tons of arguments against the singleton (of which the service is a flavor, an injected singleton, but singleton nonetheless) I find these arguments to mostly be moot and generally lack a truly elegant and concise solution. If an

Categories : Angularjs

AngularJS nested views & controllers
You need to connect your MyApp module (in its definition) with your MyApp.Admin modulelikes this: angular.module('MyApp', ["MyApp.Admin"]); But for a larger app, you might want to look at the UI-Router project instead...

Categories : Angularjs



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