我有一个带有子组件的组件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 的页面复制了一些代码,可视化代码显示错误:
此行的错误:
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) 我正在尝试制作一个上传按钮,因为我不想使用 HTML 上传按钮,如何在输入元素上调用单击事件来手动打开文件浏览器?
<div class="upload-button button" (click)="selectFile()">
Upload
<input type="file">
</div>
Run Code Online (Sandbox Code Playgroud)