public interface Module
extends com.google.gwt.core.client.EntryPoint
http://docs.angularjs.org/api/angular.Module
An Angular module represents a set of Angular components, such as controllers,
services, filters, and directives. In and of itself, module component does
not offer any added functionality. The task of registering various components
relevant to the module is done by implementing the onModuleLoad()
method.
It is recommended the code to be organized such that a single GWT module represents a single Angular module. This will help the code organized, and easier to understand, though this is not strictly enforced by the code. More advanced users may create separate sets of GWT and Angular module hierarchies and assemble them any way he wishes.
If you choose to mirror the GWT and Angular modules, then be sure to register your implementation of your Module to the GWT module descriptor as an entry point, e.g. com/example/app/MyModule.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.user.User" />
<inherits name="com.asayama.gwt.angular.NG" />
<source path="client" />
<entry-point class="com.example.app.client.MyModule" />
</module>
The corresponding MyModule class definition may look like
// In this hypothetical example, the module consists of a constant named // "pages", directive named "myHello", filter named "reverse", and two // controllers, "com.exmaple.client.FooController" and // "com.example.client.BarController". package com.example.app.client; public class MyModule extends AbstractModule { public void onModuleLoad() { Angular.module(this); constant("pages", JSArray.create(new String[]{ "Introduction", "Theory", "Design", "Implementation", "Test Methods", "Test Results", "Analysis", "Reference" })); directive(MyHello.class); filter(Reverse.class); controller(FooController.class); controller(BarController.class); } }Note that this module focuses on registering the components into a single module, and is not concerned with building the user interface. The work of building the user interface (or bootstrapping) should be the job of a GWT module, and it is recommended that this is separated from the rest of the Angular module hierarchy. For example, com/example/ui/MyEntryPoint.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module>
<inherits name="com.google.gwt.user.User" />
<inherits name="com.example.app.MyModule" />
<source path="client" />
<entry-point class="com.example.ui.client.MyEntryPoint" />
</module>
The corresponding MyEntryPoint class definition may look like
package com.example.ui.client; public class MyEntryPoint extends EntryPoint { public void onModuleLoad() { Angular.bootstrap(); } }If you follow this code organization convention, then the module dependency declared with
<inherits>
statements in *.gwt.xml files will be
consistent with the Angular module dependency (i.e. "requires" property
in AngularJS). You should have only one entry point that bootstraps the user
interface per application.
Users should consider extending AbstractModule
rather than directly
implementing this interface.
AbstractModule
Modifier and Type | Method and Description |
---|---|
void |
bind(com.asayama.gwt.angular.client.JSModule jso)
This method is used to bind the underlying AngularJS module object to
the Java wrapper.
|
<P extends Provider<?>> |
config(Class<P> klass,
Configurator<P> configurator)
Configures a provider prior to obtaining the factory from it.
|
Module |
constant(String name,
Object value)
Defines a value as a service to the module.
|
<C extends Controller> |
controller(Class<C> klass)
Registers a controller component with the module.
|
<D extends Directive> |
directive(Class<D> klass)
Registers a directive component with the module.
|
<S extends Service> |
factory(Class<S> klass)
Deprecated.
Replaced by
service(Class) |
<S extends Service> |
factory(Factory<S> factory)
Registers a service object factory with the module, so that the service
object is created if/when it is requested.
|
<F extends Filter> |
filter(Class<F> klass)
Registers a filter component with the module.
|
String |
getName()
Returns the name of the module.
|
void |
onModuleLoad() |
<S extends Service> |
service(Class<S> klass)
Registers a service class with the module, so that the service object is
created if/when it is requested.
|
<S extends Service> |
service(S service)
Registers a service object with the module.
|
Module |
value(String name,
Object value)
Defines a value as a service to the module.
|
void onModuleLoad()
onModuleLoad
in interface com.google.gwt.core.client.EntryPoint
void bind(com.asayama.gwt.angular.client.JSModule jso)
String getName()
Angular
class methods for more details.<F extends Filter> Module filter(Class<F> klass)
// Derived name is "myFilter". Java package is omitted. filter(com.example.MyFilter.class);
<D extends Directive> Module directive(Class<D> klass)
// Derived name is "myDirective". Java package is omitted. // Attribute directive usage is<div data-my-directive>
// Class directive usage is<div class="my-directive">
// Element directive usage is<my-directive>
directive(com.example.MyDirective.class);
<S extends Service> Module service(S service)
<S extends Service> Module service(Class<S> klass)
factory(new DefaultFactory(com.example.MyService.class));
@Deprecated <S extends Service> Module factory(Class<S> klass)
service(Class)
<S extends Service> Module factory(Factory<S> factory)
new
or GWT.create()
, then there is
a convenience method service(Class)
.<P extends Provider<?>> Module config(Class<P> klass, Configurator<P> configurator)
Configurator
to configure the provider injected into
the module.klass
- Provider to be configured.configurator
- Configures the provider.<C extends Controller> Module controller(Class<C> klass)
// Derived name is "com.example.MyController". factory(com.example.MyController.class);
Copyright © 2014. All rights reserved.