簡體   English   中英

更新 Angular 上的組件道具值

[英]Updating component props value on Angular

假設我有變量調用 myvariable,我想將值從 1# boolean 更新為 2# object

export class controller extends component {

  1# let myvariable = true;

   
  2# click event would update this.myvariable = { dataNew = 20 }


  3# dataView: myvariable ;

}

在 2# 我想將 myvariable 更新為 object 值 dataNew = 20,我的組件會實時了解將 3# dataView 更新為新值嗎?

是的,雖然不推薦,但它是可行的。

分配 myvariable 以鍵入 any。

import { Component, VERSION } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular ' + VERSION.major;
  myvariable: any = true;

  update() {
    this.myvariable = {dataNew: 20};
  }

}

https://stackblitz.com/edit/angular-ivy-spsiuq

暫無
暫無

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

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