How can we toggle a button to Yes/No based on JSON response in angular 2?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use following code to toggle button
import {Component, NgModule, VERSION} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
@Component({
selector: 'my-app',
template: `
<div>
<button *ngIf='toggleButton' (click)='toggleButton = false'>Button One</button>
<button *ngIf='!toggleButton' (click)='toggleButton = true'>Button Two</button>
</div>
`,
})
export class App {
name:string;
toggleButton: boolean: true; // Flag to toggle your button toggling its value on click of button
constructor() {
this.name = `Angular! v${VERSION.full}`
}
}
@NgModule({
imports: [ BrowserModule ],
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}