새 데이터를 편집하고 삽입하는 작업에 사용할 양식 구성 요소를 만들었으므로 구성 요소의 개체를 나타내는 변수를 만들었고 [(ngModel) = "schoolClass.name"그러나 다음과 같은 오류가 콘솔에 나타난다 : "schoolClass .name을"지만을 사용할 때 나타나는ngModel을 통해 변수에 액세스 할 수 없습니다. - 각도 4
ERROR TypeError: Cannot read property 'name' of null
at Object.eval [as updateDirectives] (SchoolClassFormComponent.html:5)
at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:13067)
at checkAndUpdateView (core.es5.js:12251)
at callViewAction (core.es5.js:12599)
at execComponentViewsAction (core.es5.js:12531)
at checkAndUpdateView (core.es5.js:12257)
at callViewAction (core.es5.js:12599)
at execEmbeddedViewsAction (core.es5.js:12557)
at checkAndUpdateView (core.es5.js:12252)
at callViewAction (core.es5.js:12599)
at execComponentViewsAction (core.es5.js:12531)
at checkAndUpdateView (core.es5.js:12257)
at callViewAction (core.es5.js:12599)
at execEmbeddedViewsAction (core.es5.js:12557
은 이미 다음 연산자 [(ngModel) =를 사용한 이 오류 :
ZoneAwareError {__zone_symbol__error: Error: Uncaught (in promise): Error: Template parse errors: Parser Error: The '?.' operator cannot b…, …}
message : "Uncaught (in promise): Error: Template parse errors:↵Parser Error: The '?.' operator cannot be used in the assignment at column 19 in [schoolClass?.name=$event] in ng:///SchoolClassModule/[email protected]:37 ("↵ <div class="row">↵ <div class="input-field col s12">↵ <input type="text" id="name" [ERROR ->][(ngModel)]="schoolClass?.name" name="name" class="validate">↵ ....
이들은 내 프로젝트의 요소입니다.
학교 클래스 form.component.ts :
export class SchoolClassFormComponent implements OnInit, OnDestroy {
schoolClass: SchoolClass;
.....
}
학교 클래스 form.component.html :
<input type="text" id="name" [(ngModel)]="schoolClass.name" name="name" class="validate">
학교 class.ts :
export class SchoolClass {
constructor(
private _name : string
) { }
.....
get name() : string {
return this._name;
}
set name(name : string) {
this._name = name;
}
.....
}
도와주세요!
https://stackoverflow.com/questions/45144230/conditional-ngmodel-in -angular2 – yurzui
https://github.com/angular/angular/issues/7697 – yurzui