首页 > 解决方案 > 单击复选框后如何更改标题

问题描述

这是我的片段:

import { Component, OnInit, Output } from '@angular/core';
import { EventEmitter } from 'events';

@Component({
  selector: 'app-captcha',
  templateUrl: './captcha.component.html',
  styleUrls: ['./captcha.component.css']
})
export class CaptchaComponent implements OnInit {


  captcha="click case for change title";

  peut:boolean=true;
  oui:boolean=true;
  nom:boolean=true;
  constructor() { }

  ngOnInit() {
  }

    cocher(){
      console.log(this.peut,"**");
      if(this.peut === false){ this.captcha == "title is changed!"};
    }
}
<h2 [(ngModel)]="captcha">{{captcha}}</h2>
<div>
  <mat-checkbox [(ngModel)]="peut" (change)="cocher()" >peut-être ?</mat-checkbox>
  <mat-checkbox [(ngModel)]="oui"  (change)="cocher()" >oui ?</mat-checkbox>
  <mat-checkbox [(ngModel)]="non"  (change)="cocher()">non ?</mat-checkbox>
</div>

我必须如何正确加载标题。我有一个错误的萤火虫:错误错误:没有未指定名称属性的表单控件的值访问器

谢谢您的回复

标签: angularangular-material

解决方案


像这样更改此功能的代码

cocher(){
      console.log(this.peut,"**");
      if(!this.peut){
         this.captcha ="title is changed!";
      }
    }

推荐阅读