public abstract class AbstractModule extends Object
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 that the code to be organized such that a single GWT module represents a single Angular module. This will help the code kept organized, and easier to understand, though this is not strictly enforced by this framework. 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 implements EntryPoint { 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 implements 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.Modifier and Type | Field and Description |
---|---|
protected com.asayama.gwt.angular.client.NGModule |
ngo
References to a JavaScriptObject representation known to the underlying
AngularJS framework.
|
Constructor and Description |
---|
AbstractModule() |
Modifier and Type | Method and Description |
---|---|
<P extends Provider<?>> |
config(Class<P> klass,
Configurator<P> configurator)
Configures a provider prior to obtaining the factory from it.
|
AbstractModule |
constant(String name,
Object value)
Registers an object/data structure 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 type with the module.
|
<S extends Service> |
factory(Class<S> klass)
Deprecated.
Replaced by
service(Class) since 0.0.68 |
<S extends Service> |
factory(Factory<S> factory)
Registers a service object factory instance with the module, so that the
service object is created by the factory if/when the service is
requested.
|
protected <S extends Service> |
factory(String name,
Factory<S> factory) |
<F extends Filter> |
filter(Class<F> klass)
Registers a Filter type with the module.
|
String |
getName()
Returns the name of the module.
|
<P extends Provider<?>> |
provider(Class<P> klass)
TODO Implement this method
|
<R extends Runnable> |
run(Class<R> klass)
Runs module initialization task provided by
klass . |
<S extends Service> |
service(Class<S> klass)
Registers a Service class to the module.
|
<S extends Service> |
service(S service)
Registers an instance of a Service object to the module.
|
AbstractModule |
value(String name,
Object object)
Registers an object/data structure to the module.
|
protected com.asayama.gwt.angular.client.NGModule ngo
public <P extends Provider<?>> AbstractModule provider(Class<P> klass)
klass
- @Deprecated public <S extends Service> AbstractModule factory(Class<S> klass)
service(Class)
since 0.0.68public <S extends Service> AbstractModule factory(Factory<S> factory)
new
or GWT.create()
, then there is a
convenience method service(Class)
so you do not
have to define or instantiate a custom factory.factory
- An instance of Factory object that creates a Service object.protected <S extends Service> AbstractModule factory(String name, Factory<S> factory)
public <S extends Service> AbstractModule service(Class<S> klass)
MyModule module = new MyModule();
module.factory(new DefaultFactory<S>(MyService.class));
public <S extends Service> AbstractModule service(S service)
If you have defined your own Service type, and wish to let the framework
handle the instantiation, then use service(Class)
instead.
Factory
,
DefaultFactory
public AbstractModule value(String name, Object object)
Injector.Inject
annotation within the same module. For example,
MyModule module = new MyModule();
Angular.module(module);
module.value("myValue", "Hello, World!");
module.service(MyService.class);
...
class MyService implements Service {
@Injector.Inject("myValue")
String myValue; //injector assigns "Hello, World!"
}
The concept of value in AngularJS is a useful way to manage objects
that are of module scope. With GWT, however, we can accomplish the same
thing by simply using the Java package name with public static
,
if the value is used exclusively in GWT. The method is nevertheless
useful if your module is expected to be a hybrid of GWT and JavaScript.name
- Name of the object.object
- The instance of the object.public AbstractModule constant(String name, Object value)
Injector.Inject
annotation within the same module, or to a module during configuration.
For example,
MyModule module = new MyModule(); Angular.module(module); module.constant("myConstant", "Hello, World!");The concept of value in AngularJS is a useful way to manage objects that are of module scope. With GWT, however, we can accomplish the same thing by simply using the Java package name withmodule.configure(MyServiceProvider.class, Configurator<MyServiceProvider>()
{ public void configure(MyServiceProvider provider) { //configure provider } }); ... class MyServiceProvider implements Provider {@Injector.Inject("myConstant")
String myConstant; //injector assigns "Hello, World!" }
public static
,
if the value is used exclusively in GWT. The method is nevertheless
useful if your module is expected to be a hybrid of GWT and JavaScript.name
- Name of the object.object
- The instance of the object.public <F extends Filter> AbstractModule filter(Class<F> klass)
// Derived name is "myFilter". Java package is omitted. filter(com.example.MyFilter.class);
klass
- Filter typepublic <C extends Controller> AbstractModule controller(Class<C> klass)
// Derived name is "com.example.MyController". controller(com.example.MyController.class);
klass
- Controller type.public <D extends Directive> AbstractModule 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);
Directive
- type.public <P extends Provider<?>> AbstractModule config(Class<P> klass, Configurator<P> configurator)
Configurator
to configure the provider injected into
the module.klass
- Provider type to be configured at module initialization.configuration
- Configures the provider.public <R extends Runnable> AbstractModule run(Class<R> klass)
klass
.
Whilst the task is defined as a Runnable
, the task is not
executed in a separate thread. The tasks are executed synchronously.runnable
- Module initialization task.Copyright © 2015. All rights reserved.