如何在角度2中单击更改锚标签文本 [英] How to change Anchor Tag text on Click in angular 2
本文介绍了如何在角度2中单击更改锚标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在显示"和隐藏"之间切换文本.我该怎么做?我尝试了很多,但没有工作.我不想为此使用jQuery.我只想使用角度.谁能帮我这个??
I have to toggle the text On view and Hide How do i do that? I tried many but didnt work. I dont want to use Jquery for this. I want to use only angular. Can anyone help me with this??
<a class="history-link view-history-class" id="show-view-address" (click)="view()" >View</a>
组件:
view : boolean ;
view(){
this.view = !this.view
}
为此,当我单击视图时,它将切换一个表.然后,文本应更改为隐藏".单击隐藏时也一样.
For this when i click view It will toggle a table. Then the text should change to Hide. Same when i click hide.
推荐答案
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链接- https://plnkr.co/edit/Wt8s8HSraBsnx9PzgDrA?p=preview
PLUNKER LINK - https://plnkr.co/edit/Wt8s8HSraBsnx9PzgDrA?p=preview
这篇关于如何在角度2中单击更改锚标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文