Strongloop AngularJS reflection services - angularjs

I've a Java developer who's begun working in the Javascript enterprise domain. Specifically I've begun working with Strongloop/Loopback API and AngularJS in the client.
I'm creating entities with ease with Strongloop and am very impressed with how quickly I can generate an expanded model. When it comes to the client however things appear to slow down as I have to manually create the Angular Controllers, Services and the crud template views.
I've used reflection in Java considerably in the past and I found it to be very effective. I was hoping someone might be able to let me know if there's either a reflective way to initialise Controllers so that I could have one EntityController if you like that would export the CRUD methods. Alternatively if there's a tool that might be able to access the restful api and generate generic templates, controllers and services for the restful API?
Thanks in advance for any help!
Mark.

I believe that you are looking for loopback angularjs SDK.
It will not generate views and controllers but you will have angularJS services generated that contains all the LoopBack models and methods you have defined. You have to register the AngularJS module lbServices as a dependency of your app.
Documentation covers this very well with step-by-step instructions how to setup client application.
After you setup loopback angular client, then it is easy to use models in your controllers. All you have to do is to add your model as a dependency in your controller.
If you want to avoid manual work of generating angular controllers, routes, views etc then you should consider using one of the angular application generators ( i.e. yeoman generator-angular ).
To make long story short:
use angular generator to generate angular application.
generate angular services using loopback angularjs SDK.
add loopback model as dependency to your controller or service
See also Angular SDK built-in models API

Related

How to best encapsulate Google JS API on AngularJS app

I want to use the Google JS API on my AngularJS web app. As I'm a newbie using Angular I'm a bit confused on how to encapsulate the gAPI calls. Basically I want to authenticate users and call some Google APIs (eg: spreadsheets, calendar, email, etc).
Considering a basic AngularJS app structure (main module, controllers, services, providers, etc), I decided to create a provider in order to encapsulate the Google oAuth authentication flow. And then I created some services to make the services' API call (calendar, docs, etc). Here I stated to get lost... :-\
Some questions:
How can I control (verify if the user is already authenticated) the access to my views? In each service or view controller? Or maybe on $routeProvider config?
In terms of Angular service/provider design... Is better to expose all the gAPI functionality I want to use in a Angular Service/Provider or simply access the gapi object directly in each angular controller/service?
Maybe consider using a library like https://github.com/maximepvrt/angular-google-gapi. These types of questions are hard to answer without knowing the scope of your application.
In general, I'd consider how much of the GAPI you are using and how much abstraction of the GAPI you will need. If you are doing fairly light weight things, then it may be fine to call the GAPI directly.
If you think you will be reusing the GAPI throughout the application, consider using the linked library or even wrapping the GAPI with your own services and providers.

Technologies to create a hybrid application in Cordova

This is not a programming question. If it is not appropriate to post it here, just advise me some place worth to share this.
What would be best to know in order to startup a project in Cordova. What i need to know is that in order to create a working web and android app what should i use?
So far
I use Cordova.
Ionic for GUI.
PHP and MySQL for back end
Angular JS for client side and controller for the app.
JSON
Do I have to use AJAX as well? if so, where would it fit?
"Do I have to use AJAX as well? if so, where would it fit?"
Yes, you should build a Single Page Application inside Cordova using any framework that you desire. Ionic/Angular is a valid choice here, other options include JQuery/Bootstrap, React JS, Framework7, OnsenUI and pretty much any combination of JS single page application framework and mobile focussed web front end framework that you like and can make work together.
For going beyond what the web view can do you'll use off the shelf plugins, or write your own which will need Java / Objective-C / C# or Swift skills depending on which platforms you're using.
As you want to be building a single page application you will need to make AJAX calls to get resources from servers, call APIs and the like. Do this using the mechanism built into your chosen framework, e.g. $http service with Angular, $.ajax for JQuery etc.
With angular you can use AngularJS $http
Link to Angular documentation: https://docs.angularjs.org/api/ng/service/$http

how to access process.env.endPointAPI in factories

how to access this variable "process.env.endPointAPI" in yeoman
in the factories Services ?
I want to call the API from different server?
To complement my comment to the question and to provide a more detailed answer:
It is necessary more info regarding your code. I guess you are using a yeoman generator with nodejs server side, maybe with expressjs. If that is the case then you need to pass process.env.endPointAPI via express with the help of your templating engine or change your grunt/gulp tasks to include it in a custom angular factory (for example) when you serve/build your app.
This article describes some of these situations step-by-step.
If the options in the article above don't work for you for some reason, and you are using grunt, maybe you can give grunt-ng-constant a try. Basically, it will generate you a custom constant-value utility for Angular. Once injected in your app module you can access those values from your controllers for example.

Can AngularJS work in Java EE MVC Architecture : JSP->Servlet->EJB3.1->Business Object->DAO

I have a quick question on considering AngularJS (current stable version - 1.3.9) for an upcoming application that we are building on an existing framework. The current framework has a Java EE MVC architecture and here are the current components mentioned in sequential order in which they get invoked:
View - JSPs: This layer gets as response Java Objects and we use jsp:useBean to access its properties and display on screen.
If any modifications are done on the page, it goes through a ControllerServlet i.e a Java file which has code to access the HttpRequest and HttpSession related information. The controller also does a lookup in JNDI to find the name of the bean to invoke based on the HttpRequest parameter name, e.g. PageId
Once the EJBBean lookup is returned, the controller invokes an EJB 3.1 "no-interview" view - These are Stateless Beans annotated with #Stateless
EJBBean classes then invoke BusinessObject classes, we call them "BO" which internally gets referenced by the DAO interface
A DAO implementation class is the one which is responsible for CRUD operations
Our Problems as of now:
The view is tightly coupled to Java Objects that are returned from DAOs and since the response is not converted to JSON, a lot of scriptlet code is used to display their value (I know scriplets are oldskool, but being a legacy solution there is no choice)
jQuery is used to manipulate the DOM before sending it to the controller layer
View is not the official record of whats happening on the screen, unlike AngularJS where I could easily understand
Developers write custom CSS for different browsers manually
Proposed Solution
View shall be designed for the new application using AngularJS
Take advantage of Bootstrap css classes which has readily available CSS which can be combined with AngularJS
Each request goes to ControllerServlet using $http service to ensure we use existing MVC architecture i.e routing every request through Controller
EJB Layer to be RESTFul to return data in JSON Format
Viewport specific css code for responsive web design - i.e same screen should render on multiple devices and platforms
Questions:
Is the proposed solution feasible? What are the downsides?
Is it a good practice to reference EJB Bean classes as RESTFul services?
Do we get access to all the Java EE objects / interfaces using AngularJS? For e.g. HttpRequest, HttpSession, etc.
Will it help in performing better by switching to this architecture?
Question from Management - Why not stick with jQuery! - Probably the hardest of all the questions to convince the management of Angular's benefits
Hope you guys can help throw some suggestions
i'm using spring 4.0.1 , hibernate 4.3.5 ,jackson 1.9.2 , I'm creating a RESTful webservice that returns a data in JSON format and angularjs in front-end which is loosely coupled with back-end.
concerning your questions;
the solution is feasible of course , until now there no downsides
except session management is tricky because Restful ws is stateless
.
it's provide a very elegant feature that you can access all your
functionality via any application web-client-side, desktop or
mobile.
angular app is fully isolated from back-end app you can maintain
requests and session in the server and respond with what you like in
json format to angular
same as 2
i hope it's helpful

AngularJs inject controller from different domain

I've been using DurandalJs for an application I've developed where I have a core group of functionality (JS, Html files) saved in domain XXX. I have a client app (domain YYY) that uses the JS, Html files from domain XXX. I have DurandalJs set up to inject JavaScript viewModel (and associated view) from a different domain. It's working really well.
I'm learning AngularJs and am trying to figure out how to do the same. Is it possible to inject a JavaScript resource from a different domain using AngularJs?
Thanks for your help.
Durandal uses requirejs to load resources. Angular do not have a resource loader but you can also use require. You will need to set it up yourself.
http://requirejs.org/docs/whyamd.html
There is no restriction on loading resources from different domains. The only restriction on Cross origin request is when you are using ajax.

Resources