我必须切换文本 On view 和 Hide 我该怎么做?我尝试了很多但没有奏效。我不想为此使用 Jquery。我只想使用角度。谁能帮我这个??
<a class="history-link view-history-class" id="show-view-address" (click)="view()" >View</a>
成分:
view : boolean ;
view(){
this.view = !this.view
}
为此,当我单击视图时,它将切换一个表。然后文本应更改为隐藏。当我单击隐藏时相同。
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句