Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 653
adeelmahmood Avatar asked Feb 23 '26 14:02

adeelmahmood


1 Answers

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

like image 183
ThatsWhy Avatar answered Feb 25 '26 02:02

ThatsWhy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!