button
and alert
), which should it will look like this:alerts
by clicking on the buttons
.my-cool-ngx-app
with the command:ng new my-cool-ngx-app
cd my-cool-ngx-app
ng serve
http://localhost:4200/
, which should look like this:app.component.html
and save itng add @fundamental-ngx/core
Y
:@fundamental-ngx/core
package to your direct dependencies into your package.json
and it will install it.angular.json
styles property. This will include those files as the published assets, so the application can use them.alert
and button
in app.module.ts
:import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {
ButtonModule,
AlertModule
} from '@fundamental-ngx/core';
import { AppComponent } from './app.component';
import {
BrowserAnimationsModule
} from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent
],
imports: [
AlertModule,
ButtonModule,
BrowserModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.html
:<div class="wrapper">
<button fd-button
[glyph]="'action'"
(click)="openFromComponent()">Opeb from Component</button>
<button fd-button
[glyph]="'action'"
(click)="openFromTemplate(template)">Open from Template</button>
<button fd-button
[glyph]="'action'"
(click)="openFromString()">Open from String</button>
<button fd-button
[glyph]="'sys-cancel'"
[options]="'emphasized'"
(click)="alertService.dismissAll()"
[disabled]="!alertService.hasOpenAlerts()">Dismiss All</button>
<button fd-button
[glyph]="'palette'"
(click)="toggle()">Change Theme</button>
</div>
<!-- Defining a template to open -->
<ng-template let-alert #template>
<div>{{alert.data.firstLine}}</div>
<div>{{alert.data.secondLine}}</div>
<button fd-button
[fdType]="'positive'"
[options]="'emphasized'"
[compact]="true"
(click)="alert.dismiss('Data passed back')">
Click to dismiss
</button>
</ng-template>
alert
(component
, template
, string
) and one more button for switching the themes. For that reason, we will create a new file alert-example.component.ts
, which will be used to be opened as an alert
content:import { Component } from '@angular/core';
import { AlertRef } from '@fundamental-ngx/core';
@Component({
selector: 'fd-alert-content',
template: `
<div>{{ref.data.label}}</div>
<div>It will stay open when the mouse is hovered inside.</div>
<div>Injecting AlertRef allows you to call
<code>dismiss()</code>
on the alert or access passed data.</div>
`
})
export class AlertContentComponent {
constructor(public ref: AlertRef) {}
}
alert
. In our example this is the property label
.app.component.ts
:import { Component } from '@angular/core';
import { AlertContentComponent } from './alert-content.component';
import { AlertService } from '@fundamental-ngx/core';
@Component({
selector: 'fd-alert-component-as-content-example',
templateUrl: './alert-component-as-content-example.component.html',
styleUrls: ['alert-component-as-content-example.component.scss']
})
export class AlertComponentAsContentExampleComponent {
constructor(public alertService: AlertService) { }
openFromComponent() {
this.alertService.open(AlertContentComponent, {
type: 'warning',
minWidth: '500px',
mousePersist: true,
duration: 7500,
data: {
label: 'This alert was opened by providing a component as content!'
}
});
}
openFromString() {
const alertContent = 'This is the content! The alert is not dismissible, but will disappear after 7500ms.';
this.alertService.open(alertContent, {
type: 'information',
minWidth: '500px',
dismissible: false,
duration: 7500
});
}
toggle(){}
openFromTemplate(template): void {
const alertRef = this.alertService.open(template, {
type: 'success',
duration: -1,
minWidth: '500px',
data: {
firstLine: 'This alert passes data to the template.',
secondLine: 'It also has [duration]="-1" and will not disappear automatically.'
}
});
alertRef.afterDismissed.subscribe((data) => {
// Do something after closing, receive data
// You can also manually close this alert using alertRef.dismiss()
});
}
}
app.module.ts
should look like this:import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {
ButtonModule,
AlertModule
} from '@fundamental-ngx/core';
import { AlertExampleComponent } from './alert-example.component'
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
declarations: [
AppComponent,
AlertExampleComponent
],
imports: [
AlertModule,
ButtonModule,
BrowserModule,
BrowserAnimationsModule
],
providers: [],
bootstrap: [AppComponent],
entryComponents:[AlertExampleComponent]
})
export class AppModule { }
Fundamental Library
.Fundamental Library
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
11 | |
8 | |
7 | |
7 | |
7 | |
5 | |
5 | |
5 | |
5 |