简体   繁体   中英

angular2 forms - cannot read property replace of undefined

I am following the form examples provided at Forms in Angular 2 and when I load the page I get this error

TypeError: Error loading "angualr2/forms" at <unknown> Error loading
"angualr2/forms" from "app" at http://localhost:8080/js/app.es6 Cannot
read property 'replace' of undefined

Here is the code. This is for the first data driven forms example from the blog

index.html

<my-form></my-form>

<script>
    System.paths = {
        'angular2/*' : '/quickstart/angular2/*.js',
        'rtts_assert/*' : '/quickstart/rtts_assert/*.js',
        'app' : 'js/app.es6'
    };

    //start app
    System.import('app');
</script>

app.es6

class Address {
street: string;
city: string;
state: string;
zip: string;
residential: boolean;
}

@Component({
    selector: 'my-form'
})
@Template({
    inline: '<form [form-structure]="form"></form>',
    directives: [forms] 
})
class FormExample {
    constructor(fb: FormBuilder) {
        this.address = new Address();

        this.form = fb.fromModel(address, 
            [
             {field: 'street', label: 'Street', validator: 'required'},
             {field: 'city', label: 'City', validator: 'required'},
             {field: 'state', label: 'State', size: 2, validator: 'required'},
             {field: 'zip', label: 'Zip Code', size: 5, validator: 'required'},
             {field: 'residential', label: 'Residential', type: 'checkbox'}
             ], {
            saveOnUpdate: true,
            layoutStrategy: materialDesign
    });
}
}

bootstrap(FormExample);

Any help would be appreciated

did you post all of your app.es6? Imports seem to be missing.

And: the error suggests there may be a typo in the import? angualr2 /forms --> in my example the folder name is angular2/forms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM