src/app/app.component.ts
selector | app-root |
styleUrls | ./app.component.scss |
templateUrl | ./app.component.html |
Properties |
Methods |
constructor(translate: TranslateService, config: ConfigService, document, route: Router)
|
|||||||||||||||
Defined in src/app/app.component.ts:24
|
|||||||||||||||
Parameters :
|
changeLanguage |
changeLanguage()
|
Defined in src/app/app.component.ts:58
|
set the next lang or loop to the first this is to manage future languages available
Returns :
void
|
detectCurrentTabOnRouteChange |
detectCurrentTabOnRouteChange()
|
Defined in src/app/app.component.ts:35
|
Returns :
void
|
scrollGoToTop |
scrollGoToTop()
|
Defined in src/app/app.component.ts:75
|
Returns :
void
|
switchLanguage | ||||||
switchLanguage(language: string)
|
||||||
Defined in src/app/app.component.ts:49
|
||||||
Parameters :
Returns :
void
|
toggleMenu |
toggleMenu()
|
Defined in src/app/app.component.ts:71
|
Returns :
void
|
updateCurrentTab | ||||
updateCurrentTab(event)
|
||||
Defined in src/app/app.component.ts:79
|
||||
Parameters :
Returns :
void
|
currentLang |
Type : string
|
Default value : 'fr'
|
Defined in src/app/app.component.ts:14
|
langsAvailable |
Type : []
|
Default value : ['fr', 'en']
|
Defined in src/app/app.component.ts:15
|
menuVisible |
Type : boolean
|
Default value : true
|
Defined in src/app/app.component.ts:23
|
minutes |
Type : number
|
Default value : 12
|
Defined in src/app/app.component.ts:18
|
step |
Type : string
|
Defined in src/app/app.component.ts:24
|
title |
Type : string
|
Default value : 'framadate'
|
Defined in src/app/app.component.ts:16
|
user |
Type : object
|
Default value : {
name: 'Arthur',
age: 42
}
|
Defined in src/app/app.component.ts:19
|
import {Component, Inject} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import {NavigationStart, Router} from '@angular/router';
import {DOCUMENT} from "@angular/common";
import {filter} from "rxjs/operators";
import {ConfigService} from "./services/config.service";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
currentLang = 'fr';
langsAvailable = ['fr', 'en'];
title = 'framadate';
//translation demo:
minutes = 12;
user = {
name: 'Arthur',
age: 42
};
menuVisible: boolean = true;
step: string;
constructor(private translate: TranslateService,
private config : ConfigService,
@Inject(DOCUMENT) private document,
private route: Router) {
this.translate.setDefaultLang(this.currentLang);
this.detectCurrentTabOnRouteChange();
}
detectCurrentTabOnRouteChange() {
this.route.events.subscribe((event: any) => {
});
this.route.events.pipe(filter(event => event instanceof NavigationStart)).subscribe((event:NavigationStart) => {
this.scrollGoToTop();
this.updateCurrentTab(event);
// only if there is a poll ID
this.config.fetchPollFromRoute(event);
})
}
switchLanguage(language: string) {
this.translate.use(language);
this.currentLang = language;
}
/**
* set the next lang or loop to the first
* this is to manage future languages available
*/
changeLanguage() {
let langs = this.langsAvailable;
let indexofCurrent = langs.indexOf(this.currentLang);
if (indexofCurrent > -1) {
let newIndex = indexofCurrent + 1;
if (newIndex > (langs.length - 1)) {
newIndex = 0;
}
this.currentLang = this.langsAvailable[newIndex];
}
this.translate.use(this.currentLang);
}
toggleMenu() {
this.menuVisible = !this.menuVisible;
}
scrollGoToTop() {
this.document.documentElement.scrollTop = 0;
}
updateCurrentTab(event){
if (event.url) {
const tab = event.url.split('/');
if (tab && tab[2]) {
this.step = tab[2];
} else {
this.step = 'home';
}
}
}
}
<header style="text-align:center" >
<a
[routerLink]="'home'"
class="home_link"
aria-roledescription="home"
>
<h1 >
<span class="logo_first" >Frama</span >
<span class="logo_second" >date</span > (démo)
</h1 >
<div class="legend" >proposé par
<span class="legend_first" >Frama</span >
<span class="legend_second" >soft</span >
</div >
</a >
<div id="translate_example" >
<div class="wrapper" >
<img
src="assets/img/icone-langue.svg"
alt="location icon"
(click)="changeLanguage()"
class="lang_icon clickable"
>
<img
(click)="toggleMenu()"
alt="menu icon"
class="menu_icon clickable"
src="assets/img/icone-menu.svg"
>
<select
name="language"
class="language-selector"
(change)="switchLanguage(currentLang)"
[(ngModel)]="currentLang"
>
<option
value="d"
default
class="select_language"
>{{"Language" | translate}}</option >
<option value="en" >English</option >
<option value="fr" >Français</option >
</select >
<span
(click)="toggleMenu()"
class="menu_label" >Menu</span >
</div >
</div >
</header >
<main >
<router-outlet ></router-outlet >
</main >
<framadate-debugger ></framadate-debugger >
<framadate-navigation
*ngIf="menuVisible"
[step]="step" ></framadate-navigation >
<p-toast position="top-right" ></p-toast >
./app.component.scss
@charset "UTF-8";
header {
h1,
a {
&::before,
&::after {
display: none;
}
}
}
i {
display: block;
}
.language-selector {
width: auto;
}