码迷,mamicode.com
首页 > 其他好文 > 详细

双向绑定

时间:2020-10-19 22:55:57      阅读:23      评论:0      收藏:0      [点我收藏+]

标签:void   out   root   big   template   cto   new   number   label   

<div>
    <button class="btn btn-danger" (click)="dec()" title="smaller">-</button>
    <button class="btn btn-primary" (click)="inc()" title="bigger">+</button>
    <label [style.font-size.px]="size">FontSize: {{size}}px</label>
</div>
import { Component, EventEmitter, Input, OnInit, Output } from ‘@angular/core‘;

@Component({
  selector: ‘app-sizer‘,
  templateUrl: ‘./sizer.component.html‘,
  styleUrls: [‘./sizer.component.scss‘]
})
export class SizerComponent implements OnInit {
  @Input() size = 16;
  @Output() sizeChange = new EventEmitter<Number>()
  constructor() { }

  ngOnInit(): void {
  }

  dec() { 
    // this.size-- ;
    this.sizeChange.emit(this.size - 1)
  }
  inc() { 
    // this.size++; 
    this.sizeChange.emit(this.size + 1)
  }

}

<!-- <app-sizer [size] = "size" (change)="size = $event"></app-sizer> -->
<!-- <app-sizer [(size)] = "size"></app-sizer>
<p><label [style.font-size.px]="size">FontSize: {{size}}px</label></p> -->

import { Component } from ‘@angular/core‘;

@Component({
  selector: ‘app-root‘,
  templateUrl: ‘./app.component.html‘,
  styleUrls: [‘./app.component.scss‘]
})
export class AppComponent {
  size = 16;
  title = ‘ngone‘;
  con = "OK";
  
 
}

双向绑定

标签:void   out   root   big   template   cto   new   number   label   

原文地址:https://www.cnblogs.com/dingdc/p/13841487.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!