Breaking down links in Angular4

Currently, I am working with Angular4 on the MEAN Stack and retrieving data from Mongo DB in the form of a list of hyperlinks. However, when I click on each link in the UI, they are opening as a combined link instead of separate links. To address this issue, I am attempting to add a ';' after each link in Mongo Db and then split them at the UI level based on each ';'.

<tbody>
    <tr *ngFor="let item of items">
        <td> {{ item.SNo }}</td>
        <td> {{ item.UseCase }}</td>
        <td>
            <a href="{{item.ReferenceMaterials.split(';')}}">{{ item.ReferenceMaterials }}</a>
        </td>
    </tr>
</tbody>

The JSON structure is as follows:

{
    "_id":"537437505593", 
    "SNo" :"1", 
    "UseCase":"hfwioegepepohgy", 
    "Focus":"hello world", 
    "RefernceLinks":"link1";"link2";"link3"
}

When rendered in the UI, these links appear as link1;link2;link3. Clicking on link1 opens all other links as well. Any assistance in resolving this issue would be greatly appreciated.

Answer №1

To solve this problem, you will have to develop a specialized pipe.

@Pipe({
  name: 'separate'
})
export class SeparatePipe implements PipeTransform {
  transform(value:string, separator:string):string[] {
    return value.split(separator);
  }
}

Implementation involves using the custom pipe as follows:

<a *ngFor="let link of item.Links|separate" href="{{link}}">{{link}}</a>

In case your json data structure is named item.RefernceLinks...

Answer №2

Implement ngFor.

<a *ngFor="let link of item.ReferenceMaterials" href="{{link}}">{{link}}</a>

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

Exploring Json parsing in Python with Django

I am currently using Django for my web application. I am facing an issue where I cannot access Nodes and edges by calling decoded_data['nodes']. Instead, I am encountering the error message: 'NoneType' object is not subscriptable Thi ...

What is the process for including id parameters within the URL of an HTML page?

As I work on building a website with ReactJS and webpack, I encounter the need to access URL parameters. One specific challenge I face is creating a universal blog post view page that can be dynamically loaded based on the blog id parameter in the URL. Rat ...

What is the recommended approach for including XML within JSON for an HTTP Response?

I am currently working on a project that requires me to send back a JSON object in an HTTP response, where one field contains an XML snippet as a value. Below is an example of how the object would be structured: { "driver1_url" : "https://driver.url.dow ...

Is there a way to pause the slideshow? Are there any ways I can enhance the code to make it more efficient?

Currently, I am testing a slideshow that automatically transitions every 1 second. I have set it up to pause when it reaches the first image. However, when it stops on the initial image and I click the next button, nothing happens. If I try to interact wit ...

Exploring the beauty of ASCII art on a webpage

Having trouble displaying ASCII art on my website using a JavaScript function, the output is not as expected... This is how it should appear: https://i.sstatic.net/MCwPb.png And here is the code I am trying to implement for this purpose: function log ...

After a group of floated items, there will be an automatic "clear: both" applied

Within my Content Management System, I have custom Elements that need to be floated next to each other. Instead of adding an extra div with a class of "clear", I want to automatically insert a clear: both at the end using CSS3. I attempted this workaround ...

Identify and automatically switch to the mobile site following a selection

Seeking a way to incorporate a redirect on my Joomla site that leads users to a mobile-friendly HTML5 app. After much thought, I've put together the following script: <script type="text/javascript> <!-- if (screen.width <= 800) { ...

Is it possible for me to scrape an HTML code snippet directly from a browser?

How can I extract specific content from an HTML code block using only JS or jQuery on a browser? Below is the code I am working with: <ul> <li>New York</li> <li>London</li> <li>Madrid</li> <li&g ...

The custom font is failing to load on a basic HTML website

I've been exploring different code and examples online in an attempt to incorporate a custom font into my simple HTML website. Just for reference, I'm using Django. Key files to note: aurebesh_translator.html <!DOCTYPE html> <html> ...

The charset is failing to function properly when using the French language

Encountering an issue with the French language on a website I'm currently developing ... Specifically, there are menu bars, tabs, and text within each tab involved. Upon setting charset=ISO-8859-1, the body text functions correctly, but the menu bar ...

How can I enhance the appearance of my custom field using CSS in Advanced Custom Fields?

Utilizing the Wordpress Advanced custom field plugin, I have successfully added a custom field to my site. Within this custom field, I have inserted images and now I am looking to center them on my page using CSS styles such as margin: 0 auto. If you&apo ...

Whenever I attempt to retrieve a div, I encounter an uncaught type error, specifically stating that it cannot read the property length of

As I work on integrating notifications into my rails app, I am closely following a tutorial available at Everything progresses smoothly until the point where I attempt to use JavaScript to fetch the notifications div and append notifications from a JSON E ...

How can I retrieve an array of values as individual values within a JSON object in an Android application?

String finalData = "{"Books":[{"name":"Genesis","chapters1":["Chapter No:1","Chapter No:2","Chapter No:3","Chapter No:4","Chapter No:5","Chapter No:6","Chapter No:7","Chapter No:8","Chapter No:9","Chapter No:10"]}]}; private method to extract chapters fro ...

Card with multiple links and tab-stopping

I'm trying to figure out the best way to navigate through a series of project information cards that include links to a live demo and Github Repo without overwhelming visually impaired users with excessive tab stops. I want the navigation to be seamle ...

CSS positioning problems thoroughly elucidated

I'm facing two issues that I can't seem to resolve. My goal is to recreate a design similar to the one found at https://i.sstatic.net/XfPqm.jpg. My first issue is with adjusting the box in the header to stay aligned next to my headline tags. The ...

Swap out the content in a text input box with the text chosen from a suggested autocomplete option

I am working on a text input box with auto-complete options displayed below it. I want to enable users to navigate through the options using keyboard arrows and "select" one, causing it to change color. How can I update the text in the input box with the s ...

Can the manifest.json file be edited dynamically?

I'm in the process of developing a React PWA and I'm exploring the possibility of dynamically adding icon URLs to the manifest.json file. My aim is to display a generic app icon until the user logs in. Once logged in, I plan to fetch a new icon f ...

The Bootstrap collapsible feature is causing elements to shift to the adjacent column

I'm currently implementing bootstrap's collapsible feature to showcase a list of stores along with expandable details. However, the issue arises when I expand one of the collapsibles in the left column, causing certain items to shift into the ne ...

serve angular6 application using fastify

I have a question regarding my setup. I am working on an Angular 6 application with a Fastify back-end. Fastify serves the application like this: fastify.use(['/'], serveStatic(path.join(__dirname + '/../dist/'))); The Angular build i ...

Tips for making text flow around an image

How can I achieve a design where the text wraps around an image positioned in the bottom right corner? [Image Removed by Owner] Your guidance on implementing this effect is greatly appreciated. Thank you. ...