Verify whether the message received contains a specific text within the property

Currently, I am facing a challenge with displaying a specific div in my component template only if any incoming messages contain the TYPE_OTHER property. With numerous variations of the TYPE_OTHER identifier, I am pondering on creating a condition that can identify that particular aspect of the property. However, I am uncertain about how to proceed and feel overwhelmed by trying to use a combination of ngFor and ngIf.

This is the model I am working with:

export enum MessagesType {
  TYPE_PRIMARY = "TYPE_PRIMARY",
  TYPE_SECONDARY = "TYPE_SECONDARY",
  TYPE_OTHER_1 = "TYPE_OTHER_1",
  TYPE_OTHER_2 = "TYPE_OTHER_2",
  TYPE_OTHER_3 = "TYPE_OTHER_3",
  TYPE_OTHER_4 = "TYPE_OTHER_4",
  TYPE_OTHER_5 = "TYPE_OTHER_5",
  TYPE_OTHER_6 = "TYPE_OTHER_6",
  TYPE_OTHER_7 = "TYPE_OTHER_7",
  TYPE_OTHER_8 = "TYPE_OTHER_8",
  TYPE_OTHER_9 = "TYPE_OTHER_9",
  TYPE_OTHER_10 = "TYPE_OTHER_10",
}

Template Structure:

<div class="show-if-type-other" *ngIf="
   // Condition: display this div if message.type contains 'TYPE_OTHER'    
">
  <p>{{ message.type }}</p>
</div>

Answer №1

Feel free to give this a shot

<div class="display-if-different-type" *ngIf="notification.type.includes('DIFFERENT_TYPE')">    
    <p>{{ notification.type }}</p>
</div>

Answer №2

If you want to determine if a string includes a specific set of characters, you can utilize the includes function.

*ngIf="message.type.includes('TYPE_OTHER')">

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

The showdown between AngularJS Directive Restrict A and E

In our small team, we are currently working on a project in AngularJS and striving to uphold basic standards and best practices. Since we are still relatively new to Angular, we have some questions regarding Directives, specifically the `restrict` options. ...

Is there any npm module available that can generate user-friendly unique identifiers?

Struggling to come across a user-friendly and easily readable unique ID generator for storing orders in my backend system. I have considered using the timestamp method, but it seems too lengthy based on my research. ...

Is the Vuex mutation properly formatted?

Is the mutation method correctly written to modify the initial state array? I'm uncertain about the last few lines of the mutation method. What am I missing, if anything? // Storing state: { flights: [ {trip_class: 0, number_of_change="1"}, ...

Steps for transforming an array of arrays into a JSX element within a React component, where each nested array contains its own clipPath

The array_groups variable consists of an array containing multiple arrays. Each inner array holds the coordinates of regular circles that are closely spaced together. The intention is to clipPath these inner circle arrays as a whole. When the mouse hovers ...

Animating the height of a div based on a condition with *ngIf and CSS

I am working with an angular bloc contained within a container that displays based on a *ngIf condition. <div class="simulation-bloc"> <ng-container *ngIf="type==='simulation'"> // bloc content </ng-cont ...

Stop receiving updates from an observable once you navigate away from an Onsen UI page

I am facing an issue with my Angular 2+ app that utilizes Onsen UI. I have set up some components as pages and I am using the ons-navigator to switch between them. The problem arises when I subscribe to an observable in an ons-page and the user navigates ...

How to dynamically increase vote tallies with React.js

The voting system code below is functioning well, displaying results upon page load. However, I am facing an issue where each user's vote needs to be updated whenever the Get Vote Count button is clicked. In the backend, there is a PHP code snippet ...

Content not appearing in ng repeat loop

I'm facing a basic issue that I can't seem to solve - my code isn't working as expected: <article id="desktop"> <h3>Content: </h3> <ul> <li ng-repeat="x in storage"> name: {{x.name}} ...

Enhance User Experience with React JS Multi-Select Dropdown Feature

I am dealing with 4 select dropdowns. The values selected should not be available in the remaining dropdown lists. Here is an overview of my state: this.state = { selectedDropdownArray: {}, dropdownArray: ['select', '1', &apos ...

Bidirectional enumeration in TypeScript

I am working with an enum defined as: enum MyEnum { key1 = 'val1' key2 = 'val2' } However, I am unsure how to create a SomeType implementation that fulfills the following requirements: Function: const myFunction = (param: SomeT ...

Struggling to get Tailwind typography to play nice with a multi-column React application shell

I'm currently working on a React application with TypeScript and trying to integrate one of Tailwind's multi-column application shells (this specific one). I want to render some HTML content using Tailwind Typography by utilizing the prose class. ...

Accessing URLs directly with the Angular 2 Router

I currently have a file named main.component.ts with the following code: It can be found in: root/ import {Component, OnInit, OnChanges, IterableDiffers} from 'angular2/core'; import {TypeService} from './type/type.service'; import { ...

Check out the computed typescript types

In my work with TypeScript types, I find myself frequently using Omit, Pick, and similar tools based on other types. While it generally gets the job done, I often struggle with readability when dealing with complex type manipulations. I am interested in f ...

"Safari (iOS) is experiencing a functionality issue where Alert() is working, but console.log() is

Just a heads up before you dive in: I've encountered an issue with Safari related to Chrome, but it seems to work fine on other browsers. So, it could be more OS-specific rather than a general problem. I recently ran into a frustrating situation whil ...

An effective way to incorporate internal scripts into a view within the Play Framework

Is there a preferred method for including internal JavaScript code in a Play Framework view using script tags? ...

I am having trouble with the browser detection not accurately identifying the browser I am currently using

Currently, I am working on a JavaScript code that will simply display the name of the browser being used to view the web page. Despite me using Safari, none of the navigators seem to recognize it as the current browser. The information displayed in my brow ...

How can one ensure the preservation of array values in React?

I'm struggling to mount a dynamic 'select' component in React due to an issue I encountered. Currently, I am using a 'for' loop to make API calls, but each iteration causes me to lose the previous values stored in the state. Is t ...

Guide on incorporating arrays into an array using JavaScript

Is there a way to achieve the specified outcome in JavaScript? I attempted to find a method for it on MDN but was unsuccessful. let a, b let allNumbers = [] for (a = 10; a < 60; a = a + 10) { for (b = 1; b <= 3; b++) { allNumbers.push(a ...

Best practices for effectively managing errors within JSON web tokens

I am a novice attempting to manage JWT verification. Within the function below, my goal is for the system to generate a new access token based on the refresh token if the user's access token has expired. import { asyncHandler } from "../utils/asy ...

Launching ExpressJS and ReactJS on Heroku

Currently working on a project that combines express and react. When attempting to deploy it to Heroku via git push, I encountered an error upon checking the heroku logs. The specified webpage then shows a message indicating that it cannot locate a build ...