小编Yef*_*ora的帖子

模具更改@Prop()检测

我该如何检测模板中的道具变化(角度):

但是我不知道模具中的情况如何。

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

@Component({
  selector: 'my-name',
  template: `
      <h2>First name: {{name}} ({{_name}})</h2>
  `,
})
export class ChildComponent implements OnInit {
  private _name: string;
  constructor() {}

  get name(): string {
    // transform value for display
    return this._name.toUpperCase();
  }

  @Input()
  set name(name: string) {
    console.log('prev value: ', this._name);
    console.log('got name: ', name);
    this._name = name;
  }

  ngOnInit() {
    console.log('on init');
    console.log(this._name);
  }
}
Run Code Online (Sandbox Code Playgroud)

我需要检测属性更改

angular stenciljs

2
推荐指数
1
解决办法
347
查看次数

标签 统计

angular ×1

stenciljs ×1