Manage several web addresses with a single touch

After inheriting a project in disarray, I am perplexed by the previous developer's choice to code the social icon component this way. Handling the URLs for each when clicked is proving to be a challenge. Here is where the code stands currently.

TS:

import { Component, OnInit, ElementRef, EventEmitter } from "@angular/core";
import {faFacebook, faTwitter, faLinkedin} from "@fortawesome/free-brands-svg-icons";
import { FaIconComponent } from "@fortawesome/angular-fontawesome";


@Component({
  selector: "app-social-media",
  templateUrl: "./social-media.component.html",
  styleUrls: ["./social-media.component.scss"]
})
export class SocialMediaComponent implements OnInit {
  iconTwitter = faTwitter;
  iconFaceBook = faFacebook;
  iconLinkedIn = faLinkedin;
  public static SocialMediaClicked: EventEmitter<FaIconComponent> = new EventEmitter();
  constructor() { }

  ngOnInit() {
  }
  onIconClicked(ele:FaIconComponent){
    SocialMediaComponent.SocialMediaClicked.emit(ele);
    console.log(ele);

  }

}

HTML:

<fa-icon aria-label="Twitter" class="bopd-footer-icon"
  #twitter
  (click)="onIconClicked(twitter)"
  [icon]="iconTwitter"
></fa-icon>
<fa-icon aria-label="LinkedIn" class="bopd-footer-icon"
  #linkedIn
  (click)="onIconClicked(linkedIn)"
  [icon]="iconLinkedIn"
></fa-icon>
<fa-icon aria-label="Facebook" class="bopd-footer-icon"
  #faceBook
  (click)="onIconClicked(faceBook)"
  [icon]="iconFaceBook"
></fa-icon>

Answer №1

When the user clicks on an icon, he is sharing details about social media platforms like their names. In my opinion, this information seems unnecessary and should be removed. Instead, one can implement a switch-case statement to directly manage redirection:

constructor(private router: Router) { }    

onIconClicked(ele: any) {
            switch (ele) {
                case 'twitter':
                    this.router.navigate(['your_twitter_link_here']);
                    // or window.open(link, '_blank'); to open an external link in a new tab
                    break;
                case 'linkedIn':
                    this.router.navigate(['your_linkedIn_link_here']);
                    // or window.open(link, '_blank'); to open an external link in a new tab
                    break;
                case 'faceBook':
                    this.router.navigate(['your_faceBook_link_here']);
                    // or window.open(link, '_blank'); to open an external link in a new tab
                    break;
                default:
                    break;
            }
        }

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 Chrome extension is unable to add text to the existing window

Lately, I've been attempting to develop an extension that will automatically add a div to the beginning of the current page. I've been following the guide provided on this https://developer.chrome.com/extensions/activeTab page. The code from the ...

How to use Jquery to fetch the value of a td element nested inside another

After consulting the manual, I am trying to find a way to extract the value in the second column of a table when a specific span is clicked. However, the challenge is that the click event is currently being triggered by the first span cell. Here is the jQu ...

What is the process for delineating a smaller object within a larger one?

The current data structure I am handling: this.currentData = [ { "1304": { "id": 6458, "data": "Data1", "created_at": "2020-10-20 23:16:38", "updated_at": & ...

Ending a timed function in AngularJS 1

As part of my Angular JS 1 learning journey, I am working on a small test involving text areas that display text using Angular functions when a user enters and exits them. The enter function has a 3-second delay, while the exit function waits for 5 seconds ...

Anticipating the arrival of the requested data while utilizing Ajax sending

Greetings, I'm currently utilizing JavaScript to send a request and receive a response from the server. xxmlhttp.open("GET","ajax_info.txt",true); xmlhttp.send(); myotherMethod(); I am looking for a way to ensure that the next set of instructions ar ...

Transferring mouse events from iframes to the parent document

Currently, I have a situation where my iframe is positioned over the entire HTML document. However, I am in need of finding a way to pass clicks and hover events from the iframe back to the main hosting document. Are there any potential solutions or alter ...

Changing content of inline editable data table in Vuetify through a method

I am facing a challenge while attempting to update the value in my inline edit data table from a method. The issue lies in the fact that the item I pass is not getting updated. In my cancel method, I pass props.item to be updated. While props.item.iron pr ...

The code coverage for the "rendering expectations" test in a particular component is insufficient

In order to test a specific component in my application, I am utilizing react-test-render. The test is intended to ensure that the component renders properly. Despite defining all the necessary properties for the component in the test file, the test cover ...

Tips for creating a mirrored image on an IcosahedronGeometry using three.js

My goal is to create a rotating IcosahedronGeometry in three.js and have it reflect an image on the front side of the geometry. After successfully creating the IcosahedronGeometry and implementing rotation on its axis, I encountered an issue when trying t ...

Preventing Event Bubbling with Hammer.js 2.0: A Step-by-Step Guide

I have a situation with a parent and child div. I want to prevent panning or dragging on the child from affecting the parent. I came across a similar question that was asked a year ago, but I am using a newer version of Hammer.js with the jQuery wrapper. ...

What is the best way to customize image transparency using javascript?

Looking to create a webpage that shows an image for a specified duration before smoothly transitioning to another image that includes a clickable link. Wondering how to accomplish this using javascript? I am aware that it can be done with Flash, but it mu ...

When using Next.js getServerSideProps(), cookies are not accessible on the initial render after a redirect, but they become available upon refreshing the page

Within my Next.js application, I am serving cookies from the server-side API like this: res.setHeader('Set-Cookie', AJWT) res.redirect(302, '/') Now, in my index.js file, I am attempting to retrieve the cookie before the page is render ...

It appears that the pixel sizes are different than what was originally designed

In my project, I have a header panel where the burger button is designed with a width of 32px and height of 24px. .header { display: flex; font-weight: bold; font-size: 50px; height: 100px; border: 1px solid black; position: relativ ...

JavaScript code to retrieve an image from an <img> tag's source URL that only allows a single request and is tainted due to cross-origin restrictions

I have an image displayed in the HTML DOM. https://i.stack.imgur.com/oRgvF.png This particular image (the one with a green border) is contained within an img tag and has a URL as its source. I attempted to fetch this image using the fetch method, but enc ...

What is the best way to transfer a querystring received in Node.js to a page being shown through res.render?

I have a nodejs file where I am rendering a page named foo.html. Within foo.html, I am using ajax to retrieve variables from a querystring and load an appropriate xml document based on those variables. The issue arises when I run my nodejs server, which is ...

Unconventional Quirks of Equalizing Arrays from Split CSV Strings

Update - It appears that we might be dealing with a localized bug. Further testing is required to confirm... I have a CSV String (containing spaces) that resembles the following: var myString = "Here is a value, I am an important value, One last value" ...

Exceljs : 'An issue has been identified with certain content in the document named "file.xlsx"(...)'

I have encountered an issue with an xlsx file generated using Exceljs. While I have been creating csv files in my project without any problems, creating an xlsx file now poses an error. The xlsx file opens clean on Ubuntu/LibreOffice Calc, but there is an ...

Choose several identifiers that possess strikingly similar titles

I am dealing with a form that is dynamically generated by a third-party provider and unfortunately I am unable to modify it... However, I am looking for a solution to select all IDs that begin with the same string, such as: easi_fielddiv_LastName, easi_fi ...

What is the best way to decompress a gzip response body from a NodeJS request module?

How can I decompress a gzipped body in a request's module response? I have attempted various methods from different sources online, but none of them seem to be effective. request(url, function(err, response, body) { if(err) { handleError ...

Add an unidentified element into a sealed directive's scope

Is it possible to inject a value into a directive's close scope? I couldn't find any information about this in the angularjs documentation, so I decided to experiment. Does anyone know of a more elegant solution to this issue? Here is my current ...