我正在尝试使用JavaScript代理来检测对象数组中的更改。
问题:每当删除或插入数组发生变化时,我都希望得到该删除或插入的项目。
当前代码
target = [{ id: 1, a: 'a' }, { id: 2, a: 'b' }];
proxy = new Proxy(target, {
get: function (target, property: string, receiver) {
if (property === 'pop') {
console.log('deleted object', target[target.length - 1]);
}
console.log('get', property);
// property is index in this case
return target[property];
},
set: function (target, property, value, receiver) {
console.log('set', property, 'to', value);
target[property] = value;
// you have to return true to accept the changes
return true;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 ES6 代理。我已经创建了一个数组的代理,现在当我检查代理的类型时,它给我作为Object类型。
问题:
如何检查我创建的代理是用于数组还是对象?
例子:
const arr = ['a', 'b', 'c'];
const arrProxy = new Proxy(arr, {});
alert(typeof(arrProxy));Run Code Online (Sandbox Code Playgroud)
更新(解决方案):typeof我们应该使用
而不是使用Array.isArray
const arr = ['a', 'b', 'c'];
const arrProxy = new Proxy(arr, {});
alert(Array.isArray(arrProxy));
Run Code Online (Sandbox Code Playgroud) 我在 angular6 应用程序中使用角材料。
<mat-form-field fxFlex>
<mat-label [class.form-label]="fg.get('email').valid && fg.get('email').touched">{{attributesLabels.email}}</mat-label>
<input matInput formControlName="email" required [autofocus]="true">
<mat-error *ngIf="fg.get('email').hasError('required')">Email is required</mat-error>
<mat-error *ngIf="fg.get('email').hasError('email') && !fg.get('email').hasError('required') ">Invalid email</mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
这是必填字段,在此输入字段的占位符中,“*”附加在占位符之后,如下所示:

我想将占位符中“*”的颜色更改为红色。我怎样才能改变颜色?
Html 由上面的 mat-form-field 生成:
问题:
我创建了一个formGroupusing formbuilder. FormGroup 有一个控件,其.名称中有。现在,当我尝试formControl使用formGroup.get方法时,它返回null。
代码
export class AppComponent implements OnInit {
name = 'Angular';
obj = {};
formGroup: FormGroup;
constructor(private formBuilder: FormBuilder) {
}
ngOnInit() {
this.obj["parent.child"] = new FormControl();
this.obj["parent"] = new FormControl();
this.formGroup = this.formBuilder.group(this.obj);
// All controls
console.log(this.formGroup.controls);
// This is the problem its not geting the form control if I have '.' in the name of form control.
console.log(this.formGroup.get("parent.child"));
// If I am getting …Run Code Online (Sandbox Code Playgroud) 我想分享一个与 lodash debounce 相关的问题,但是当我尝试在 Stackbiltz ( angular project) 中使用 lodash 时,它给了我模块未找到错误。
问题:
我已经在依赖项中安装了 lodash,但它仍然给我错误:
lodash module not found在 stackbiltz 这是链接: https: //stackblitz.com/edit/angular-a5pvrq
我需要的?:
我需要在 stackbiltz 中使用 lodash 来实现角度。
更新:(解决方案) 依赖项中缺少@types/lodash。
我正在尝试使用 Kendo Angular Components 创建垂直条形图,但在文档中找不到任何示例或配置。
以下是图表文档的链接: https: //www.telerik.com/kendo-angular-ui/components/charts/
那里有一个显示水平条的条形图,但我需要垂直条。
问题:
我需要使用 Kendo Angular Components 创建垂直条形图。
angular ×3
es6-proxy ×2
javascript ×2
arrays ×1
charts ×1
css ×1
formgroups ×1
html ×1
lodash ×1
module ×1