Ng2.x 常见错误总结。

1.EXCEPTION:… caused by: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as ‘standalone’ in ngModelOptions.

  
  原因:Angular2规定,当在表单中使用 [(ngModel)] 时,必须要定义 name 属性。没有name属性就会报上面的错误

  解决办法:给表单标记添加name属性即可

2.加载的模板不显示 Error: Uncaught (in promise): Failed to load xxx.html

moduleId - ES/CommonJS module id of the file in which this component is defined

1
2
3
4
5
@Component({
moduleId: module.id, //加上这句就可以了
selector: 'xxx-xxx',
templateUrl: 'xxx.component.html' //外部模板
})