[英]angular 2 want to define an array inside the object so that i can push some value
I want to define array inside the object I am using dot notation but it is always showing undefined 我想在使用点符号的对象内定义数组,但始终显示未定义
my HTML code 我的HTML代码
<mat-checkbox *ngFor="let q1 of question.checkboxes;" (change)="checkboxSelected(q1,question,$event)"> {{q1.name}} </mat-checkbox>
my ts code 我的ts代码
checkboxSelected(selected,obj,event){obj.box.push('somecondition') }
it is showing an error that 它显示一个错误
ERROR TypeError: Cannot read property 'push' of undefined
Check if property "box" exists inside your object "question". 检查对象“问题”中是否存在属性“框”。
If it exists, check whether it is initialized properly ie question.box = [] 如果存在,请检查是否已正确初始化,即question.box = []
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.