Passed
Push — develop ( ba9cf0...098d47 )
by Franck
02:32
created

HomeComponent.useLanguage   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
import { Component, OnInit } from "@angular/core";
2
import { Subscription } from "rxjs";
3
import { ProductsService } from "src/app/services/products.service";
4
import { Response } from "src/app/models/response";
5
import { TranslateService } from '@ngx-translate/core';
6
7
@Component({
8
    selector: "app-home",
9
    templateUrl: "./home.component.html",
10
    styleUrls: ["./home.component.scss"]
11
})
12
export class HomeComponent implements OnInit {
13
14
    products;
15
    productSub;
16
17
    constructor(private ProductsServices: ProductsService, public translate: TranslateService) {
18
        translate.addLangs(['fr', 'en']);
19
        translate.setDefaultLang('fr');
20
    }
21
22
    ngOnInit(): void {
23
        this.productSub = this.ProductsServices.getProducts().subscribe (
24
            (response: Response) => {
25
                this.products = response.result;
26
            },
27
            (error) => {
28
            }
29
        )
30
    }
31
32
    useLanguage(language: string): void {
33
        this.translate.use(language);
34
        }
35
36
    switchLang(lang: string) {
37
        this.translate.use(lang);
38
    }
39
}
40