小编Pri*_*cee的帖子

Angular 2 ngfor first,last,index loop

我试图将此示例中的第一个设置为默认值:plunkr

收到以下错误:

Unhandled Promise rejection: Template parse errors:
TypeError: Cannot read property 'toUpperCase' of undefined ("dButtonToggleGroup">
                                                            <md-button-toggle [ERROR ->]*ngFor="let indicador of indicadores; #first = first" value="indicador.id" [checked]="first">
      "): ng:///AppModule/HomeComponent.html@35:78
Parser Error: Unexpected token #, expected identifier, keyword, or string at column 31 in [let indicador of indicadores; #first = first] in ng:///AppModule/HomeComponent.html@35:78 ("       <md-button-toggle *ngFor="let indicador of indicadores; #first = first" value="indicador.id" [ERROR ->][checked]="first">
                                                                <span>{{ indicado"): ng:///AppModule/HomeComponent.html@35:153
Run Code Online (Sandbox Code Playgroud)

怎么了??

angular-material angular

59
推荐指数
3
解决办法
8万
查看次数

Angular 2 Reactive Forms 找不到控件

林新与活性形式和进出口试图使具有分量indicadoresanswers

有了这个组件:

addAnswers(indicador: Indicador, answer?: any):void {
    const indicadoresFormArray = <FormArray>this.customForm.controls['indicadores'];

    let label = answer ? answer.label : '';
    let value = answer ? answer.value : '';

    let superi = 0;
    for(let i = 0; i < indicadoresFormArray.length; i++) {
        if(indicadoresFormArray.value[i].id == indicador.id) {
            superi = i;
        }
    }

    (<FormArray>(<FormGroup>(indicadoresFormArray).controls[superi])
    .controls['answers']).push(
        new FormGroup({
            label: new FormControl(label),
            value: new FormControl(value)
        })
    )
}
Run Code Online (Sandbox Code Playgroud)

还有模板

<div *ngFor="let indicador of customForm.controls['indicadores'].controls">
<div class="row" *ngFor="let answer of indicador.controls['answers'].controls">
    <div class="input-field …
Run Code Online (Sandbox Code Playgroud)

angular angular-reactive-forms

4
推荐指数
1
解决办法
5502
查看次数