File

src/app/app.component.ts

Metadata

selector app-root
styleUrls ./app.component.scss
templateUrl ./app.component.html

Index

Properties
Methods

Constructor

constructor(translate: TranslateService, config: ConfigService, document, route: Router)
Parameters :
Name Type Optional
translate TranslateService No
config ConfigService No
document No
route Router No

Methods

changeLanguage
changeLanguage()

set the next lang or loop to the first this is to manage future languages available

Returns : void
detectCurrentTabOnRouteChange
detectCurrentTabOnRouteChange()
Returns : void
scrollGoToTop
scrollGoToTop()
Returns : void
switchLanguage
switchLanguage(language: string)
Parameters :
Name Type Optional
language string No
Returns : void
toggleMenu
toggleMenu()
Returns : void
updateCurrentTab
updateCurrentTab(event)
Parameters :
Name Optional
event No
Returns : void

Properties

currentLang
Type : string
Default value : 'fr'
langsAvailable
Type : []
Default value : ['fr', 'en']
menuVisible
Type : boolean
Default value : true
minutes
Type : number
Default value : 12
step
Type : string
title
Type : string
Default value : 'framadate'
user
Type : object
Default value : { name: 'Arthur', age: 42 }
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;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""