Angular 角度2-基于JSON响应的切换按钮
如何根据angular 2中的JSON响应将按钮切换为是/否?使用以下代码切换按钮Angular 角度2-基于JSON响应的切换按钮,angular,angular2-template,angular2-forms,angular2-services,Angular,Angular2 Template,Angular2 Forms,Angular2 Services,如何根据angular 2中的JSON响应将按钮切换为是/否?使用以下代码切换按钮 import {Component, NgModule, VERSION} from '@angular/core' import {BrowserModule} from '@angular/platform-browser' @Component({ selector: 'my-app', template: ` <div> <button *ngIf='tog
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/core'导入{Component,NgModule,VERSION}
从“@angular/platform browser”导入{BrowserModule}
@组成部分({
选择器:“我的应用程序”,
模板:`
按钮一
按钮二
`,
})
导出类应用程序{
名称:字符串;
toggleButton:boolean:true;//切换按钮的标志单击按钮时切换其值
构造函数(){
this.name=`Angular!v${VERSION.full}`
}
}
@NGD模块({
导入:[BrowserModule],
声明:[App],
引导:[应用程序]
})
导出类AppModule{}
通过编写一些代码。如果你甚至不知道从哪里开始,那就读一本关于angular的书,或者官方文档/教程,然后练习。如果你知道从哪里开始,那么展示你已经尝试过的,并解释你面临的具体问题。这太宽泛了。Meta已经决定我们不应该回答糟糕的问题,特别是那些希望让StackOverflow看起来像一个代码编写服务的问题。这将有助于鼓励未来的不良问题充斥网站。仅供参考,我已经发布了我尝试过的内容@OptimusPrime为什么你要发布一个重复的问题呢?如果这是一个后续问题,你为什么不把这个问题和你的新问题联系起来?如果这是重复的,则应将其删除。