簡體   English   中英

如何在角度切換2(材質-工具欄)中調用方法?

[英]How to call method in slide toggle angular 2 (material - tool bar)?

HTML FILE

  <div class=" -toolbar "> <p> <mat-toolbar> <h4>Offer Mapping</h4> <div class="row align-right col-md-offset-7 col-md-1 "> <mat-form-field class="button-spacing"> <mat-select placeholder="select"> </mat-select> </mat-form-field> <button mat-raised-button (click)="campaignPrioritise()" [disabled] class="button-spacing"> Prioritise </button> <button mat-icon-button color="primary" (click)="createNewCampaign()"> <mat-icon aria-label="Example icon-button with a heart icon">add_circle_outline</mat-icon> </button> <mat-slide-toggle *ngIf= "let element" class="material-icons color_green" matTooltip="Prioritise" [checked]="element.priority" (change)="campaignPrioritise(element)"></mat-slide-toggle> </div> </mat-toolbar> </p> </div> 

TS文件

import { Component } from '@angular/core';
import { MatTableDataSource } from '@angular/material';



/**
 * @title Basic use of `<table mat-table>`
 */
@Component({
  selector: 'table-basic-example',
  styleUrls: ['table-basic-example.css'],
  templateUrl: 'table-basic-example.html',
})
export class TableBasicExample {
  timeSelection1 = '';
  timeSelection2 = '';

  selected: any[] = [];
  selected1 : any[] = [];



on(element){
  let priority = false;
        element.priority = !element.priority;
}

}

當我滑動切換開關時,優先級變量變為true和false,這是怎么實現的?這是Mat工具欄,我試圖編寫一些代碼,但是滑動切換開關未顯示在Mat工具欄上!
當我按下撥動開關時,優先級開關為true,而向左滑動撥動開關為false。 這是我的StackBlitz鏈接-https://stackblitz.com/edit/toggle12345677709-gfj1 ? file = main.ts

上面的代碼中沒有聲明任何element ,如果您有該element它將正常工作

element:any = {
   priority: false
 }

on(){
  let priority = false;
  this.element.priority = !this.element.priority;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM