求助。 从Angular 2切换到Angular 5时,发生错误:
ERROR TypeError: Cannot read property 'name' of undefined
at checkBindingNoChanges (core.js:9902)
at checkNoChangesNodeInline (core.js:13951)
at checkNoChangesNode (core.js:13925)
at debugCheckNoChangesNode (core.js:14754)
at debugCheckDirectivesFn (core.js:14656)
at Object.eval [as updateDirectives] (GeneralFormComponent.html:4)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:14638)
at checkNoChangesView (core.js:13763)
at callViewAction (core.js:14116)
at execComponentViewsAction (core.js:14068)
控制台引用GeneralFormComponent中的行错误:
<input type="hidden" class="form-control" [(ngModel)]="model.guid" name="guid">
调试后,我意识到该组件被调用了2次。第一次,模型只是初始化,模型实际上是空的,在模型中第二次来自数据库的数据。 我认为这个错误源于这样一个事实,即一些数据突然被新的数据所取代。
帮助解决问题。
答案 0 :(得分:0)
以理查兹的建议为基础
也许这会有所帮助?
<ng-container *ngIf="model != null && model.guid!=null">
<input type="hidden" class="form-control" [(ngModel)]="model.guid" name="guid">
</ng-container>