我正在关注Forms in Angular 2提供的表单示例,当我加载页面时出现此错误
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
这是代码。这是针对博客
中的第一个数据驱动表单示例的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);
任何帮助将不胜感激
答案 0 :(得分:1)
你发布了所有app.es6吗?进口似乎不见了。
并且:错误表明导入中可能存在拼写错误? angualr2 /表格 - &gt;在我的例子中,文件夹名称是angular2 / forms