Struggling with syntax errors while attempting to use ngIf to dynamically switch images in Angular 8

As a newcomer to the Angular world, I'm facing challenges when it comes to displaying different images based on ngx-translate methods. For instance, if the user selects English from the language dropdown, the image with English text should be displayed; and if Mandarin is chosen, then the corresponding image with Mandarin text should appear. Below is the snippet of code that I've tried using ngIf:

Here is the relevant code from both the ts and html files. Thank you in advance for your assistance :)

.ts file:

import { Component, ViewChild, ViewEncapsulation } from '@angular/core';
import { NgbCarousel, NgbSlideEvent, NgbSlideEventSource } from '@ng-bootstrap/ng-bootstrap';
import {
  trigger,
  state,
  style,
  animate,
  transition
} from '@angular/animations';
import {TranslateService} from '@ngx-translate/core';
import {_} from '@biesbjerg/ngx-translate-extract/dist/utils/utils';
import defaultLanguage from "../../assets/i18n/en.json";

@Component({
  selector: 'ngbd-carousel-pause', 
  templateUrl: './carousel-pause.html',
  encapsulation: ViewEncapsulation.None,
  styles:[`
      // Styles go here
  `]
})
export class NgbdCarouselPause {

  constructor(private translate: TranslateService) {
    translate.setTranslation('en', defaultLanguage);
    translate.setDefaultLang('en');
}

useLanguage(language: string) {
  this.translate.use(language);
}

// More functionality goes here...

.html file:

<!-- HTML code goes here -->

Answer №1

Utilize the translateCurrentLang method

Modify the following line

<div ngIf="translate==='en'">

to this new line

<div ngIf="translate.currentLang === 'en' ">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular - Show labels instantly, without needing their values

My component is designed to show users' attributes such as their name and email. I want to display the labels right away, without having to wait for the values to be fetched. I did find a solution, but I'm not satisfied with it because it involve ...

Is there a way to apply a predetermined color scheme to an image with PHP?

Currently, I am seeking advice on how to limit the color range of an image to a specific predetermined palette. My goal is to experiment with converting images to pure black and white, 16 colors, 64 colors, and more. Unfortunately, I am unable to utilize ...

What strategies can I employ with flexbox to achieve my design goals?

How can I achieve my design requirements using flexbox? design requirements The current code that I have implemented follows the flexbox approach to meet the design requirements. However, the output of this code does not match the screenshot of my design ...

The combination of jQuery, Internet Explorer, and dynamic navigation tabs

Currently, I am in the process of creating a website navigation. The navigation is designed with a tabbed style menu that is very straightforward. As you hover over each tab, the tab transitions from red with white text to white with red text. When you mov ...

How do I create a standalone .ts file with Angular 9?

Just diving into Angular development and eager to create a standalone .ts file without having to generate an entire component. Can anyone guide me on how to achieve this using ng generate? Scenario: During the application build process, I need to write th ...

`resolve() and then() taking precedence over asynchronous operations`

I recently came across a tutorial on promises that explained: const promise = new Promise((resolve, reject) => { // Perform asynchronous tasks // If successful resolve(); // If fails reject(); }); After trying to implement this, I haven't had ...

The Bootstrap 4 alignment class for centering rows is not functioning as expected

<div class="row align-items-center remember"> <input type="checkbox" class="form-control" checked>Remember Me </div> <div class="row align-items-center"> <input type=& ...

Difficulty with the D3.js grid and tick functionality

Dealing with x-axis grid line formatting issues in a D3.js graph that I've created. var data = [{ x: '12-May-12', y: 5 }, { x: '30-Apr-12', y: 28 } // more data points listed here var margin = { top: 30, ...

Firefox changes the sequence of form input attributes

Is anyone familiar with this issue and how to prevent it? I am using AJAX to populate a div with a form from a PHP file. The input element is generated in PHP as shown below: echo ('<input type="text" name="court_type_name" id="court_type_name_in ...

Fixing a menu hover appearance

I recently encountered a small issue with the menu on my website. When hovering over a menu item, a sub-menu should appear. However, there seems to be a slight misalignment where the submenu appears a few pixels below the actual menu item. Check out the w ...

data being released from variables in angular ionic

I am truly perplexed as to why the variables aren't holding their values. I've declared a variable user and initialized it with data from the userData() function. However, it appears as undefined when I log it within the constructor as well as ...

Dynamically remove the underline tag from a table cell

Within my HTML, I've inserted the code below for a cell: cell.innerHTML = "<u>View All</u>"; In my onclick event for the cell, I have this code (for example, it's based on a condition where I structure the content as shown below, no ...

Minimize the gap between icon and text on paper-icon-item in Polymer

Is there a way to decrease the spacing between the icon and text in paper-icon-item? I'm looking for a solution to this issue. https://i.sstatic.net/kZ9sy.png I attempted the following: paper-icon-item { --paper-item-icon: { padding-right: 0; ...

Tap on the menu icon / Swipe on the screen to move between pages

I recently created a website, but I'm looking to add a unique feature where users can click and drag horizontally to navigate between pages. This means that when dragging from right to left, the page turns to the next menu page. Similarly, dragging fr ...

Table header sticking does not work when overflow is set to scroll or auto

After trying numerous solutions without success, I am reposting this question. My table has a horizontal scroll and I attempted to make the table header sticky using position:sticky, but it caused the scrolling functionality to stop working. Is there a wa ...

Issue with Nebular where the token payload is not being received properly after logging in

Currently, I am utilizing the nebular framework alongside the Laravel API by integrating the NbPasswordAuthStrategy and NbAuthJWTToken class. Here is an example configuration: NbAuthModule.forRoot({ strategies: [ NbPasswordAuthStrategy.setup({ ...

Extracting PartialView contents as a string

I am looking to embed HTML code that is rendered by a PartialView. For instance, var partView = PartialView("myView", myModel); string content = ??; What should I replace the question marks with? ...

Employing a lexicon of hexadecimal color code values to harmonize CSS styles

I have a unique requirement where I need to utilize a dictionary of HTML color codes and then apply those colors as styles. It's an interesting challenge! Here is an example of how my color dictionary looks like: const colorCodes = { red: ...

How can I give focus to an input element within a React component without directly using a ref on the input tag?

I am struggling to maintain focus on my text input boxes after the component re-renders. While I know I can use a ref to apply focus to an <input> element (as mentioned in responses here), I face limitations when the <input> is nested within a ...

PHP and issues with search functionality

I am currently working on developing a search function to retrieve and display data from a MySQL database based on user selection. However, I encountered an error that I am not sure how to resolve. Can anyone provide assistance? I am fairly new to PHP. The ...