我在Angular 4中尝试嵌套的反应形式.它工作正常但是当我尝试构建AOT时它会抛出错误
'AbstractControl'类型上不存在'controls'
我用Google搜索并尝试了一些事情,但没有运气.谁能告诉我如何解决这个问题?
<div [formGroup]="myForm">
<div formArrayName="addresses">
<div *ngFor="let address of myForm.get('addresses').controls; let i=index"
class="panel panel-default">
<span *ngIf="myForm.get('addresses').length > 1"
(click)="removeAddress(i)">Remove</span>
<div [formGroupName]="i">
<mat-form-field>
<input matInput formControlName="city" placeholder="city" value="">
</mat-form-field>
</div>
</div>
</div>
<a (click)="addAddress()" style="cursor: default"> Add +</a>
</div>
Run Code Online (Sandbox Code Playgroud)
下面的打字稿代码
constructor(private _fb: FormBuilder) {
}
ngOnInit() {
this.myForm = this._fb.group({
addresses: this._fb.array([
this.initAddress(),
])
});
}
initAddress() {
return this._fb.group({
city: ['']
});
}
addAddress() {
const control = <FormArray>this.myForm.get('addresses');
control.push(this.initAddress());
}
removeAddress(i: number) {
const control = …Run Code Online (Sandbox Code Playgroud) 我试图用可选择和可移动的选项实现角度垫片.但问题是占位符在加载时移动到顶部.我不知道我在代码上做了什么错.请有人帮我解决这个问题.
在下面添加了GIF
<mat-form-field>
<mat-chip-list #chipList>
<mat-chip *ngFor="let keyword of keywords" [selectable]="selectable"
[removable]="removable" (remove)="remove(keyword)">
{{keyword}}
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
<input placeholder="Keywords"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event)" />
</mat-chip-list>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
和ts是
visible: boolean = true;
selectable: boolean = true;
removable: boolean = true;
addOnBlur: boolean = true;
separatorKeysCodes = [ENTER, COMMA];
keywords= []; // At time load i need this to be empty
public add(event: MatChipInputEvent): void {
let input = event.input;
let value = event.value;
if ((value || '').trim()) …Run Code Online (Sandbox Code Playgroud) typescript angular-ui angular-material angular-material2 angular
如果我的问题很愚蠢,我很抱歉,我有 30 多个静态 ng-container 和一些独特的静态 #hashtagID,但我想在 ngFor 的帮助下动态创建它们
public lists = ['food', 'book', ........, 'cook']
Run Code Online (Sandbox Code Playgroud)
期待输出:
<ng-container #food></ng-container>
<ng-container #book></ng-container>
..
..
<ng-container #cook></ng-container>
Run Code Online (Sandbox Code Playgroud)
所以我几乎尝试了所有方法但没有运气,
1: <ng-container *ngFor="#id of lists"><ng-container>
2: <ng-container *ngFor="let id of lists" #{{id}}><ng-container>
3: <ng-container *ngFor="let id of lists" #+"id"><ng-container>
4: <ng-container *ngFor="let id of lists" #{id}><ng-container>
5. <div *ngFor="let id of lists" #id></div>
6: <div *ngFor="let id of lists" [id]="id">
Run Code Online (Sandbox Code Playgroud)
我在 .ts 文件中使用这个 #hashTagID 作为 viewContainerRef。
@ViewChild('food', {read: ViewContainerRef }) 私人食物:ViewContainerRef;
请有人帮我解决这个问题。
下面的抛出代码给出了lint错误预期对象将被丢弃
throw { code : 403, message : myMessage };
Run Code Online (Sandbox Code Playgroud)
如果我尝试抛出新的Error,我不会被拖延,但会在响应中显示[Object Object]。
throw new Error({ code : 403, message : myMessage });
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何解决“ 预期对象抛出错误”吗?不删除eslint配置/规则
如果我的问题很愚蠢,请原谅我。但请有人告诉我或建议我如何解决这个问题。其实我有很大的多维数组
像这样
$array_value = Array
(
[0] => Array
(
[0] => sdfsf
[1] => fghbfh
[2] => sgddfsg
[3] => ujmnm
[4] => jkluik
..
..
..
..
..
..
[150] => jhbjhbjh
)
[1] => Array
(
[0] => 44062
[1] => 45503
[2] => 44062
[3] => fdg
[4] => dfgdg
..
..
..
..
..
..
[150] => jhbjhbjh
)
....
....
....
[590] => Array
(
[0] => 44062
[1] => 45503
[2] => 44062 …Run Code Online (Sandbox Code Playgroud) 对不起,如果我的问题很愚蠢,但我们的应用程序面临延迟问题。KEYPRESS 事件处理程序是罪魁祸首。我们在整个应用程序中使用以下指令。它KeyPress通过HostListener. 按下键时,该指令使用正则表达式检查值,并preventDefault在条件为假时执行。
private regexMap = { // add your own
'999': /^([0-9]){0,3}$/g,
'9999': /^([0-9]){0,4}$/g,
...
...
}
@HostListener('keypress', [ '$event' ])
public nInput(event: KeyboardEvent) {
// Allow Backspace, tab, end, and home keys
if (this.specialKeys.indexOf(event.key) !== -1) {
return;
}
this.pattern = this.regexMap[this.validationFormat];
const current: string = this.el.nativeElement.value;
const next: string = current.concat(event.key);
if (next && !String(next).match(this.pattern)) {
event.preventDefault();
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题。会debounceTime解决这个问题吗?我不确定如何向此方法添加去抖动。请有人帮我解决这个问题。
我有变量$ est_date ="25-02-2015"这是DD-MM-YYYY格式所以现在我需要在mysql表中插入这个值,列类型是DATE TIME,所以我试过这样但是日期不是存储在coloumn est_date中,它只显示00-00-0000
$mysqli = new mysqli('localhost','root','','smart_marine');
$insertdate = date("d-m-Y", strtotime($est_date));
$insert = $mysqli->prepare("INSERT into repair (
cont_details_id,
depot_details_id,
cont_condition,
est_cost,
currency,
est_date,
location
)
VALUES (?,?,?,?,?,?,?)");
$phpArray = json_decode($serialize_data, true);
foreach ($phpArray as $key => $value)
{
if($value['rate']!=''&& $value['drop']!='')
{
$insert->bind_param('sssssss',
$value['id'],
$depot_details_id,
$value['drop'],
$value['rate'],
$currency,
$insertdate,
$location);
$insert->execute();
}
}
Run Code Online (Sandbox Code Playgroud)
请有人帮助我.
我也试着像这样存放
$insert->bind_param('sssssss',
$value['id'],
$depot_details_id,
$value['drop'],
$value['rate'],
$currency,
STR_TO_DATE($est_date , '%d-%m-%Y'),
$location);
but this return error "undefined function STR_TO_DATE"
Run Code Online (Sandbox Code Playgroud) 我试图取消选择角度2中的单选按钮。我尝试了以下代码,但无济于事。
.html
<div [formGroup]="myForm">
<mat-radio-group matInput (click)= "resetRadio($event)" formControlName="RdoSel">
<mat-radio-button *ngFor="let RadioOpt of RadioOpts" [value]="RadioOpt .id">{{RadioOpt .value}}</mat-radio-button>
</mat-radio-group>
</div>
Run Code Online (Sandbox Code Playgroud)
.ts
public RadioOpts= [
{ id: 'Market', value : 'Market'},
{ id: 'Segment', value : 'Segment'}
];
public resetRadio(event: any) {
if(myForm.get('RdoSel').value===event.target.value){
myForm.get('RdoSel').setValue('false');
}
Run Code Online (Sandbox Code Playgroud)
当我console.log(event.target.value)返回div标签。有人可以告诉我如何取消选择角度2中的单选按钮吗?
我试图为其中任何一个提供通用方法的打字匹配。在下面的示例中,我有一个预定义的方法识别,它接受通用类型。现在我想定义 OR 类型来识别,它应该接受人或位置。
身份方法来自我无法修改的第三方库。当我尝试下面的场景时,它返回了一个错误
Argument of type '{ city: string; country: string; }' is not assignable to parameter of type 'Person | Location'.
Type '{ city: string; country: string; }' is missing the following properties from type 'Location': ancestorOrigins, hash, host, hostname, and 9 more.
Run Code Online (Sandbox Code Playgroud)
function identity<Type>(arg: Type): Type {
return arg;
}
interface Person {
name: string;
age: number;
}
interface Location {
city: string;
country: string;
}
identity<Person | Location>({city: 'SA', country: 'USA'})
Run Code Online (Sandbox Code Playgroud) angular ×5
typescript ×5
javascript ×2
php ×2
angular-ui ×1
angular5 ×1
arrays ×1
date ×1
ecmascript-6 ×1
eslint ×1
foreach ×1
mysql ×1
mysqli ×1
polymer ×1
throw ×1