Components Manual
Create a component
Using the Angular CLI to generate a new component.
You can use the ng generate (or just ng g) command to generate Angular components:
The CLI creates a new folder
src/app/NewComponent/
and generates four files: .ts, .scss, .html and .spec.ts.For example if you generate a component called Client, the NewComponent class file is as follows:
It's important to mention that all control components in WebMAP extends from ControlComponent class as follow:
Class metadata properties meanings
selector
— the component's CSS element selectortemplateUrl
— the location of the component's HTML template file.styleUrls
— the location of the component's private CSS styles.
Add an
<wm-client>
element to the AppComponent template file to display it.Add its respective directives into the HTML file to complete ControlComponent inheritance as follow:
One-way binding : []
Example of one-way binding:
Two-way binding : [()]
Example of two-way binding:
Possible blueprints in the table below
Scaffold | Usage |
Component | ng g component my-new-component |
Directive | ng g directive my-new-directive |
Pipe | ng g pipe my-new-pipe |
Service | ng g service my-new-service |
Class | ng g class my-new-class |
Guard | ng g guard my-new-guard |
Interface | ng g interface my-new-interface |
Enum | ng g enum my-new-enum |
Module | ng g module my-module |
Remote Data Binding
The WebMap BackEnd requires to have a WebAPI controller that responds to the component's data queries. This controller should be in charge of identifying the data that will be sent to the controller.
Some components work on single data, like a TextBox
or a Label
, but other components handle a collection of data, like a ComboBox
or a Grid
.
To handle those data collections the component requires to bind the data source to a remote service. Below are the steps required to bind remote data to the component.
Create a property in the
*.component.ts
file that will be used to bind the value in theHTML
, and another property that will be used to hold the URL to query the server for data that belongs to API on assets.Include the
WebMapService
in the constructor, the dependency injection from Angular will be in charge of providing the service when needed.Implement the
ngOnInit
event by calling theWebMapService
and setting the returned data to theitems
property.
Imports
In every new component some Angular imports must be added, these imports are used for special purposes like detect changes, render styles correctly and use the Web Map 5 native services. There are three mandatory services:
ChangeDetectorRef
: It is used to detect model changes and refresh every model change in the component.Renderer2
: It provides an easy and safe way to modify DOM elements.ElementRef
: It allows the access to the component root DOM element.
The first step is import the angular classes needed:
*This is an example, more imports can be included as is needed for each component.
And the second and the last one step is add the classes in the constructor and pass their definitions to the base constructor.