Angular 2-基于JSON响应的切换按钮 [英] Angular 2 - Toggle button based on JSON response

查看:64
本文介绍了Angular 2-基于JSON响应的切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何基于角度2中的JSON响应将按钮切换为是/否"?

How can we toggle a button to Yes/No based on JSON response in angular 2?

推荐答案

使用以下代码切换按钮

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 {}

这篇关于Angular 2-基于JSON响应的切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆