Using Ng If with a boolean value to dynamically update the title of a webpage

On my Stock page, I have multiple fields labeled as Title 1.

https://i.sstatic.net/FpCsW.png

When I run a console.log, it indicates that I am on the first page!

ngOnInit() {
    this.currentPortfolio = this.shrd.getData('currentPortfolio');
    this.subPage = 'stocks';
    this.sectionTitle = "";
    this.pageTitle = "Options";
    for (var i = 0; i < this.optionsDropdownFilters.length; i++) {
        this.issuers.actionsGrouped[this.optionsDropdownFilters[i]] = [];
    }

    console.log("First page => Tile 1 : " + JSON.stringify(this.subPage = 'stocks'));
    this.initiate();
}

In Google Chrome, the display looks like this: https://i.sstatic.net/UcC1j.png

Next, when I click on the Search button on my Stock page... I want to change from Title1 to Title2.

https://i.sstatic.net/TyY80.png

Running a console.log now indicates that I am on the second page.

https://i.sstatic.net/OnSNI.png

launchSearchSelected(t) {
    this.searched = true;
    this.dateNotValid = false;
    this.dateDoesntExist = false;
    if (this.search.equityDate.length == 0) {
        this.dateDoesntExist = true
    }
    if (t == 'A' && this.search.equityOptionCode > 0 && this.search.equityDate.length > 0) {
        this.launchSearchResult(t, this.search.equityOptionCode, this.search.equityDate);
    } else if (t == 'I' && this.search.indexOptionCode.length > 0 && this.search.indexDate.length > 0) {
        this.launchSearchResult(t, this.search.indexOptionCode, this.search.indexDate);
    }
    console.log("Second Page => Title 2 " + JSON.stringify(this.searched = true));
}

Confusion arises in my HTML regarding how to toggle between the titles using boolean values.

<ng-container *ngIf="subPage  === 'stocks' ">
   <div class="breadcrumb d-flex justify-content-between">
      <h1>Title 1  </h1>
   </div>
</ng-container>

Answer №1

Without more context, it's difficult to determine the best course of action. However, if your goal is to modify the title based on the value of the this.subPage variable being "stocks" or not, you can achieve this by:

<ng-container>
   <div class="breadcrumb d-flex justify-content-between">
      <h1 *ngIf="subPage == 'stocks'">Title 1</h1>
      <h1 *ngIf="subPage != 'stocks'">Title 2</h1>
   </div>
</ng-container>

Answer №2

I found the answer!

<ng-container *ngIf="subPage  === 'stocks' ">
   <ng-container *ngIf="spinners.search  === true ">
      <div class="breadcrumb d-flex justify-content-between">
         <h1>Title 1 </h1>
      </div>
   </ng-container>
</ng-container>
<ng-container *ngIf="subPage  === 'stocks' ">
   <ng-container *ngIf="spinners.search  === false ">
      <div class="breadcrumb d-flex justify-content-between">
         <h1>Title 2 </h1>
         <button (click)="goBack()" class="btn btn-primary"> Back
         </button>
      </div>
   </ng-container>
</ng-container>

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

Unable to view the refreshed DOM within the specifications after it has been altered

For my current project, I am working on writing a functional spec that involves using Mocha/JSDOM and making assertions with 'chai'. The specific use case I am tackling is related to the function called updateContent: When this function is exec ...

Developing a progress bar with jQuery and Cascading Style Sheets (

Below is the code I'm currently using: <progress id="amount" value="0" max="100"></progress> Here is the JavaScript snippet I have implemented: <script> for (var i = 0; i < 240; i++) { setTimeout(function () { // this repre ...

Animation of active chat list items on Whatsapp

Has anyone figured out a simple method to create an animation like the one in Whatsapp? For example, when you are on a chat screen and go back to the chat list, have you noticed how an active element is briefly highlighted in gray (to indicate which chat ...

What is the reason behind this Uncaught TypeError that is happening?

After converting my questionnaire to a PHP file and adding a validation script, I encountered an error: Uncaught TypeError: Cannot set property 'onClick' of null The error is pointing me to line 163 in my JavaScript file, where the function f ...

Having trouble adjusting the width and height of images to a full 100% scale

I'm currently working on an Angular and Bootstrap application where I am trying to integrate a Bootstrap carousel. However, I've encountered some resizing issues with the width and height of the images/graphs. You can view a demo of the issue he ...

Header should elegantly glide up and down as the user scrolls through the page

I've implemented a top div on my page that houses contact details and social media links. I've managed to hide it during scrolling and make it reappear when reaching the top of the page. However, I'm hoping to smoothen this transition with a ...

Using Selenium WebDriver to Extract Variables from JavaScript SourceCode

Currently, I am dealing with a web page source code that utilizes JavaScript to display text. Below is an excerpt from the source: var display_session = get_cookie("LastMRH_Session"); if(null != display_session) { document.getElementById("sessionDIV") ...

Interactive table with dynamic data retrieval

I need help displaying data dynamically from a datatable using an API. The API I am working with is located at this URL and I am utilizing the bootstrap4 datatable. You can also find my code on this JSFiddle. Can someone provide guidance or an example on h ...

Express.js code is experiencing difficulties with autocomplete functionalities

jQuery autocomplete code example [Express JS code for retrieving data][2\ Example of fetching data in Express JS ...

I am looking to transfer information from Angular 4 to Java servlet (cross-domain)

Having trouble sending data from Angular 4 to a Java servlet due to access control restrictions. Need to figure out how to properly insert data into the database using the Java servlet. Here is my code snippet: import { Injectable } from '@angular/ ...

How to eliminate undefined values from a dropdown selection in AngularJS

Blockquote When choosing a material from the column, the first option is showing as undefined. How can I remove undefined from the drop-down list? What changes need to be made in the HTML/JSON data for this to work properly? Blockquote var app = ang ...

Using Angular service worker to pre-fetch video files

Issue arises when the service worker prefetches the entire video embedded on the page, leading to performance problems. My ngsw-config.json only contains configurations for local files, whereas the video is located on a different subdomain under /sites/def ...

Difficulty loading AngularJS 1.3 page on Internet Explorer 8

Being an avid user of Angular, it pains me to even bring up the topic of IE8, a browser that many consider to be pure evil and deserving of extinction. Despite my reservations, I am experiencing difficulties with loading Angular 1.3 in IE8. The page break ...

When working with Typescript and React, you may encounter an issue where an element implicitly has an 'any' type because the type 'State' has no index signature. This can lead to

In my current mini project, I am using Typescript and React. As someone new to Typescript, I am currently in the process of learning it. Within the project, I have a state defined as follows: type State = { field1: string, field2: string, field3: n ...

NuxtJS (Vue) loop displaying inaccurate information

I have a dataset that includes multiple languages and their corresponding pages. export const myData = [ { id: 1, lang: "it", items: [ { id: 1, title: "IT Page1", }, { ...

Wcf Service does not define Angular JS methods

I am utilizing a WCF Service within an AngularJS application. The WCF Service is functional, and I am attempting to display a list of user records from a SQL database. However, upon running the application, I encountered the following errors: angular.js: ...

Utilize a single JavaScript script to handle numerous HTML forms within the same webpage

I am currently facing an issue with a page that contains multiple forms needing the same JavaScript code. This specific code is designed to add more input fields to the form, which it does successfully. However, the problem lies in the fact that it adds in ...

Implement a dynamic loading feature using AJAX, pushState, and Jekyll for a

In an effort to create a standard template for our studio's Jekyll sites development, I am aiming to implement page animation transitions. My plan involves loading different content from each page using AJAX and utilizing pushState to update the URL a ...

React Router - Implementing a <Redirect> element rather than a list of child components

Here is the code snippet I am working with: import { Redirect } from 'react-router-dom'; import QPContent from '../QPContent'; class AnswerContainer extends Component { constructor(props) { super(props); this.state = { ...

What could be causing the issue with Vite build and npm serve not functioning together?

After shifting from CRA to VITE, I am encountering a problem with serving my app. I successfully build my app using vite build. and can serve it using Vite serve without any issues. However, I want to use npm's serve command. Whenever I run vite bui ...