小编mat*_*att的帖子

如何检测对 Angular 中属性的更改

我有一个带有子组件的组件timeline

<app-timeline [(editing)]="editingDate"></app-timeline>
Run Code Online (Sandbox Code Playgroud)

在时间轴组件中,我有这些属性:

@Input() editing: boolean; // <--- detect change on this
@Output() editingChange = new EventEmitter();
Run Code Online (Sandbox Code Playgroud)

如何检查editing时间线组件何时发生属性更改?每当编辑值发生变化时,我都需要发出编辑值。

我应该为编辑属性使用 setter 然后从那里发出吗?

private _editing
set editing() { ... // emit }
Run Code Online (Sandbox Code Playgroud)

或者还有其他方法吗?

angular

11
推荐指数
2
解决办法
2万
查看次数

KeyboardEvent:“EventTarget”类型上不存在属性“value”

我从 Angular 的页面复制了一些代码,可视化代码显示错误:

此行的错误:

map((e: KeyboardEvent) => e.target.value),
Run Code Online (Sandbox Code Playgroud)

错误

Property 'value' does not exist on type 'EventTarget'.
Run Code Online (Sandbox Code Playgroud)

来自 Angular网站的代码:

import { fromEvent } from 'rxjs';
import { ajax } from 'rxjs/ajax';
import { map, filter, debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';

const searchBox = document.getElementById('search-box');

const typeahead = fromEvent(searchBox, 'input').pipe(
  map((e: KeyboardEvent) => e.target.value),
  filter(text => text.length > 2),
  debounceTime(10),
  distinctUntilChanged(),
  switchMap(() => ajax('/api/endpoint'))
);

typeahead.subscribe(data => {
 // Handle the data from the API
});
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

9
推荐指数
1
解决办法
6668
查看次数

如何使用 Angular 调用输入元素上的单击事件

我正在尝试制作一个上传按钮,因为我不想使用 HTML 上传按钮,如何在输入元素上调用单击事件来手动打开文件浏览器?

<div class="upload-button button" (click)="selectFile()">
   Upload
   <input type="file">
</div>
Run Code Online (Sandbox Code Playgroud)

html angular

6
推荐指数
2
解决办法
3万
查看次数

标签 统计

angular ×3

html ×1

javascript ×1

typescript ×1