我正在使用Angular 2,我想分别验证每行中的控件.但我没有办法做到这一点.我希望它只使用反应形式而不是使用模板驱动的方法.我想要每个都有[formGroup] <tr>.任何帮助将不胜感激.以下是我的代码结构:
<tbody *ngFor="let single of allTeamDetails"
[ngClass]="{'alternate-row-color': $even}">
<tr>
<td class="td-data first-column">
<input type="text" class="input-text form-control"
[value]="single.first_name">
</td>
<td class="td-data second-column">
<input type="text" class="input-text form-control"
[value]="single.last_name">
</td>
<td class="td-data third-column">
<input type="email" class="input-text form-control"
[value]="single.email">
</td>
<td class="td-data fourth-column">
<select class="selection-dropdown width-80-percent"
[value]="single.user_role">
<option *ngFor="let singleRole of allUserRole"
value="{{singleRole.name}}">
{{setUserRoleAndType(singleRole.name)}}</option>
</select>
</td>
<td class="td-data fifth-column" >
<input type="password" class="input-text form-control">
</td>
<td class="td-data sixth-column" >
<input type="password" class="input-text form-control">
</td>
<td class="td-data save-send-tm-data">
<button class="btn save-user-details save-sub-account-details" …Run Code Online (Sandbox Code Playgroud) function Product(name, price) {
this.name = name;
this.price = price;
}
const p1 = new Product('Pen', 20);
const p2 = Object.create(p1);
console.log(p1.constructor.prototype === p1.__proto__); // true
console.log(p2.constructor.prototype === p2.__proto__); // false
Run Code Online (Sandbox Code Playgroud)
我的理解是这两个总是相等的(如第一个console.log陈述)。
但是,在进行一些调整时,我发现了这个令人惊讶的结果(第二个console.log声明)。
有人可以澄清我对prototype和之间关系的理解__proto__。提前致谢!
我有 2 个组件:TopBarComponent和UserDetailsComponent. TopBarComponent对所有页面都是通用的,因此UserDetailsComponent也一起加载。我添加了一个名为UserDetailsService.
UserDetailsService.ts:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from "rxjs/BehaviorSubject";
import { Observable } from "rxjs/Observable";
@Injectable()
export class UserDetailsService {
public userData = new BehaviorSubject({});
public setUserDetails(data: any) {
this.userData.next(data);
}
public getUserDetails(): Observable<any> {
return this.userData.asObservable();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在UserDetailsService从TopBarComponent
TopBarComponent.ts
//setting data in Shared Service
this.userDetailsService.setUserDetails(result.data);
Run Code Online (Sandbox Code Playgroud)
当我订阅服务中的 getter 方法时,它总是只返回 的初始值BehaviorSubject。
用户详细信息组件.ts
this.userDetailsService.getUserDetails().subscribe(
data => {
console.log(data); //prints …Run Code Online (Sandbox Code Playgroud) 我在组件中添加了::ng-deep用于引用内容投影元素的合并器。但是,当我从默认(ViewEncapsulation.Emulated)切换到ViewEncapsulation.ShadowDom模式(显然::ng-deep不是本地Shadow DOM选择器)时,旧的CSS无法正常工作。
/* This works in ViewEncapsulation.Emulated */
:host ::ng-deep .course-description {
max-width: 360px;
margin: 0 auto;
margin-top: 15px;
user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
出人意料的是,当我使用/deep/的组合子(这是在Chrome V63去除https://developers.google.com/web/updates/2017/10/remove-shadow-piercing)正在罚款ViewEncapsulation.ShadowDom在Chrome v75.0.3770.100
/* This works in ViewEncapsulation.ShadowDom */
:host /deep/ .course-description {
max-width: 360px;
margin: 0 auto;
margin-top: 15px;
user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
是否可以::slotted()在组件CSS内使用以使其像以前一样在ViewEncapsulation.ShadowDom模式下工作?如果是,怎么办?
在将Angular Content Projection <ng-content>与HTML的ShadowDOM(ShadowDOM Visualizer)进行比较时,我发现了一个细微的区别。
在上述链接页面中,当我删除in 标记的select属性时,所有其他内容都将附加到标头组件。<content><header>
在Angular中,仅收集没有选择器的元素并将其附加到通配符 <ng-content></ng-content>
在查看以上链接时,我在技术上怀旧。因此,我想到了这个问题。
注意:我从Shadow DOM上的Google Developer的Web基础知识重定向到该链接。
我是 React Native 的新手。我想FlatList在向左滑动时为删除项目设置动画。我获取了滑动的值并能够删除该项目,但并不顺利。
所以,我正在使用AnimatedReact Native 的 API,并希望在滑动后 1000 毫秒内使 FlatList 项目的高度为 0。
我正在使用输入范围和输出范围。但我无法获取当前元素的高度,因为所有元素的高度都是动态的。
我没有在 Angular 项目中使用 HttpIntercepter,并且我想在出现错误时检索一些自定义响应标头。我{ observe: 'response' }在 POST API 调用中尝试过:
post(url, data = ''): Observable<any> {
url = this.baseApiUrl + url;
const headers = this.createHttpHeaders();
const body = JSON.stringify(data);
return this.http.post(url, body, {headers: headers, observe: 'response'}).pipe(catchError(HttpClientHelper.handleError));
}
Run Code Online (Sandbox Code Playgroud)
但我只收到 4 个标头:
error.headers.keys().map( (key) => console.log(key + ':' + error.headers.get(key)));
回报
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-length: 0
expires: 0
pragma: no-cache
但是,x-不会返回带有前缀的自定义响应标头。是否有任何配置可以检索自定义响应标头?
我想使用Ionic / React本机创建混合应用程序。在我的应用程序中,我将创建贴纸,我想将这些贴纸上传到WhatsUp。我怎样才能做到这一点?
<mat-error>在子 ControlValueAccessor 组件中没有父formControl验证的影响。
<!-- Parent component template -->
<app-unique-name-text-box [formControl]="categoryName"></app-unique-name-text-box>
Run Code Online (Sandbox Code Playgroud)
// Parent Component ts
this.addCategoryForm = fb.group({
'categoryName': ['', Validators.compose([Validators.required, BlankSpaceValidator.validate])]
});
this.categoryName = this.addCategoryForm.controls['categoryName'];
Run Code Online (Sandbox Code Playgroud)
<!-- Child component template -->
<mat-form-field class="example-full-width">
<input matInput placeholder="Name" [formControl]="uniqueNameControl" (blur)="onInputBlur()">
<mat-error *ngIf="errorState">Enter a unique name</mat-error>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
// Child component ts
import {Component, OnInit, Optional, Self} from '@angular/core';
import {ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR, NgControl} from '@angular/forms';
import {distinctUntilChanged} from "rxjs/operators";
@Component({
selector: 'app-unique-name-text-box',
templateUrl: './unique-name-text-box.component.html',
styleUrls: ['./unique-name-text-box.component.scss']
})
export class UniqueNameTextBoxComponent implements …Run Code Online (Sandbox Code Playgroud) 由于Math.sign()按照https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Math/sign接受数字参数或数字作为字符串,为什么给出以下结果,以及如何给出提供这些结果时发生了内部转换?
console.log(Math.sign([])); // 0
console.log(Math.sign([20])); // 1
console.log(Math.sign([20, 30, 40])) // NaNRun Code Online (Sandbox Code Playgroud)