Custom services
You can create custom services in which you can progam (re-usable) logic on UI side.
Add Typings/declare the interface
👉 Choose Shared UI
in the main menu and then Typings
.
Add a new Typing declaration if you don't have already one and name it: Typings
Replace app_namespace with the namespace of your app and declare your interface. For example:
declare namespace HelloWorld.NgLayer.Services {
interface ITestService {
test(): boolean;
}
interface IAnotherService {
sayHello(): string;
}
}
Create the User Interface service
👉 Choose User interfaces
in the main menu.
Select the Angular user interface. Select the RELATED
tab.
Choose SERVICES
on the left.
Add a new Service:
- Name: the name of your service, for example TestService.
- Interface: the interface that your service implements, note that this is also your Angular injection token. For example: ITestService
- Source: code your service by implementing your interface.
Using your custom service in an Angular component
Open a custom Angular component and inject your service in the constructor of your component, for example:
constructor(
@Inject('ITestService')
private _testService: wy.ITestService) {
}
You can now consume your service within your Angular custom component.