How to change anchor tag text on click in angular 2


Prakash

I have to toggle text On view and Hide how can I do this? I tried a lot but it didn't work. I don't want to use Jquery for this. I just want to use angular. Can anyone help me with this? ?

<a  class="history-link view-history-class" id="show-view-address" (click)="view()" >View</a>

Element:

view : boolean ;
    view(){
            this.view = !this.view
        }

For this, when I click on the view, it switches a table. Then the text should change to hidden. Same when I click hide.

Rahul Singh
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'

@Component({
  selector: 'my-app',
  template: `
    <div>
      <a href = "#" (click) = "on()">{{value}}</a>
    </div>
  `,
})
export class App {

  value  = "View";
  toogle = true;

  on(val:boolean){
    //either this
    this.value = (!this.toogle)?"View":"Hide";
    this.toogle = !this.toogle;

    //or this
    this.value = (this.value == "View")?"Hide":"View"; // and remove toogle
  }

}

@NgModule({
  imports: [ BrowserModule ],
  declarations: [ App ],
  bootstrap: [ App ]
})
export class AppModule {}

PLUNKER link - https://plnkr.co/edit/Wt8s8HSraBsnx9PzgDrA?p=preview

Related


How to change anchor tag's text on click using jquery?

Start I want to change the text of anchor tag on click event using jquery. Anchor Tag: <a id="view_email" href="#"><i class="fa fa-envelope"></i> View Email</a> query code: <script type="text/javascript"> $(document).ready(function(){ $("#view_email").cl

Click on anchor tag with text

Tania How to click on anchor tag with specific text? For example, I have the following anchors in my page <a>one</a> <a>two</a> <a>three</a> Now, the user enters one. How to click a label with text as one? I tried this: var uservar='one'; $('a [text=$uservar]

Click on anchor tag with text

Tania How to click on anchor tag with specific text? For example, I have the following anchors in my page <a>one</a> <a>two</a> <a>three</a> Now, the user enters one. How to click a label with text as one? I tried this: var uservar='one'; $('a [text=$uservar]

Change anchor tag's text on click in ng-click method

username I have an anchor tag that when clicked should change its text in the ng-click function. Can someone please help me? Here is the code: <div ng-app="Test"> <div ng-controller="Foo"> <a class="anchClass" ng-click="hi($event)">click me</a> </div> an

Change anchor tag's text on click in ng-click method

username I have an anchor tag that when clicked should change its text in the ng-click function. Can someone please help me? Here is the code: <div ng-app="Test"> <div ng-controller="Foo"> <a class="anchClass" ng-click="hi($event)">click me</a> </div> an

Angular 5 click bind to anchor tag

javiroyeda I need to bind the click event on the template's anchor: My html looks like this: <a (click)="deleteUser(user)"> <i class="la la-trash"></i> </a> useris the previous variable*ngFor="let user of users" The function is declared deleteUser()in my

Angular 5 click bind to anchor tag

javiroyeda I need to bind the click event on the template's anchor: My html looks like this: <a (click)="deleteUser(user)"> <i class="la la-trash"></i> </a> useris the previous variable*ngFor="let user of users" The function is declared deleteUser()in my

Angular 5 click bind to anchor tag

javiroyeda I need to bind the click event on the template's anchor: My html looks like this: <a (click)="deleteUser(user)"> <i class="la la-trash"></i> </a> useris the previous variable*ngFor="let user of users" The function is declared deleteUser()in my

Angular 5 click bind to anchor tag

javiroyeda I need to bind the click event on the template's anchor: My html looks like this: <a (click)="deleteUser(user)"> <i class="la la-trash"></i> </a> useris the previous variable*ngFor="let user of users" The function is declared deleteUser()in my

Angular 5 click bind to anchor tag

javiroyeda I need to bind the click event on the template's anchor: My html looks like this: <a (click)="deleteUser(user)"> <i class="la la-trash"></i> </a> useris the previous variable*ngFor="let user of users" The function is declared deleteUser()in my

Angular 5 click bind to anchor tag

javiroyeda I need to bind the click event on the template's anchor: My html looks like this: <a (click)="deleteUser(user)"> <i class="la la-trash"></i> </a> useris the previous variable*ngFor="let user of users" The function is declared deleteUser()in my

How to map/loop 2 array values to anchor tag with href and text?

jaish I am trying to map values from 2 different arrays, one containing links and the other containing tab names . I have an anchor tag consisting of href and text string . Is there a way I can map/loop over the values in the 2 arrays to provide the values. Ap

Change anchor text after click with jQuery

caustic I am using the following code to show/hide a div when an anchor is clicked. $(document).ready(function(){ $(".slidingDiv").hide(); $(".show_hide").show(); $('.show_hide').click(function(){ $(".slidingDiv").slideToggle(); });

Change anchor text after click with jQuery

caustic I am using the following code to show/hide a div when an anchor is clicked. $(document).ready(function(){ $(".slidingDiv").hide(); $(".show_hide").show(); $('.show_hide').click(function(){ $(".slidingDiv").slideToggle(); });

Dynamically change content of div with angular anchor tag

Encoders you want to know I'm having a problem with how to load dynamic views using Angularjs in anchor tags. By the way, I can't use ng-view because ng-view can only be used once in the template. So I was thinking of using ng-src, but in the example document

Dynamically change content of div with angular anchor tag

Encoders you want to know I'm having a problem with how to load dynamic views using Angularjs in anchor tags. By the way, I can't use ng-view because ng-view can only be used once in the template. So I was thinking of using ng-src, but in the example document

Change class of anchor tag using angular js

Upendra Sharma I'm having some problems changing the class of an anchor tag. I define a hyperlink with a data target property. I want to change the class of this hyperlink using angularjs. Like data-target='#upen' it should first select the element using query

In Angular, how to change the text of a button on click

anonymous I want to change the text when this.isDisabledset to false and vice versa when the button is clicked. I used this.btn.valuethat too but it gave me an error. import { Component } from '@angular/core'; @Component({ selector: 'app-root', template:

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag from javascript or jquery

151291 There is an anchor tag, try to click it from javascript, it doesn't respond, and when the page loads, it goes to next.phpwithout manually clicking the anchor tag . How to archive it? <!DOCTYPE html> <html> <head> <title></title> <script src="jqu

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag using Selenium WebDriver

Shubham Mishra: I can't click the button with some visibility issues. I need to hover over the link before clicking the same link. <a tabindex="0" class="cardPreviewLink expand-icon" aria-label="card opens in new tab" target="_blank" id="card-p

How to click anchor tag from javascript or jquery

151291 There is an anchor tag, try to click it from javascript, it doesn't respond, and when the page loads, it goes to next.phpwithout manually clicking the anchor tag . How to archive it? <!DOCTYPE html> <html> <head> <title></title> <script src="jqu

How to avoid page refresh on anchor (<a></a>) tag click?

Pepe Perez I am creating a dynamic website. My problem is when I click on the following tabs: <a class="s-inte" href="set_interesantes.php?n=Frank Melo&u=f6e79cfe9c0ecc4c08dac4c860c4802b&back=http://localhost:8085/Something/success/profile.php?search_user=f6e7

How to avoid page refresh on anchor (<a></a>) tag click?

Pepe Perez I am creating a dynamic website. My problem is when I click on the following tabs: <a class="s-inte" href="set_interesantes.php?n=Frank Melo&u=f6e79cfe9c0ecc4c08dac4c860c4802b&back=http://localhost:8085/Something/success/profile.php?search_user=f6e7