关于在modal中select和radio组件默认选中的问题 #6892
Unanswered
ouxingning
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
我有一个列表页面 (list component), 里面有个button,关键代码如下:
<button nz-button nzType="primary" (click)="createEditModal(0)">添加
点击”添加“按钮,会弹出一个modal,这个modal的创建代码如下:
createEditModal(attributeId: number) {
const modalTitle = attributeId > 0 ? '编辑' : '添加';
}
其中的AttributeEditComponent是 另外一个编辑组件,里面定义了一些表单,主要的模板代码如下:
类型 请选择类型 是否为规格属性 {{item.label}} 是否启用 {{item.label}} 提交 重置这个编辑组件的typescript代码如下:
@component({
selector: 'app-attribute-edit',
templateUrl: './attribute-edit.component.html',
styleUrls: ['./attribute-edit.component.scss']
})
export class AttributeEditComponent implements OnInit {
@input()
attributeId: number = 0;//属性id
@input()
categoryId: number = 0; // 属性分类
@input()
isSpec: number = 0; // 是否规格属性
categoryList: AttributeCategory[] = [];
isSpecList = [{ value: 0, label: '否' }, { value: 1, label: '是' }];
isEnabledList = [{ value: 1, label: '启用' }, { value: 0, label: '禁用' }];
form!: FormGroup;
constructor(
private fb: FormBuilder,
private modalRef: NzModalRef,
private productAttributeService: ProductAttributeService,
private productAttributeCategoryService: ProductAttributeCategoryService,
private messageService: MessageService
) {
}
ngOnInit(): void {
this.form = this.fb.group({
name: ['', [Validators.required]],
categoryId: [this.categoryId, [Validators.required]],
isSpec: [0],
isEnabled: [1],
});
}
这个编辑组件里定义了两个输入参数,categoryId和isSpec,希望实现的效果是,在表单的select组件中根据入参category的值默认选中某项,在表单的radio组件里根据入参isSpec的值默认选中某个单选项。我在测试的时候发现这两个入参的值能打印出来,但是默认选中的效果一直实现不了,没有默认选中某项的状态,麻烦大家帮我看看是怎么回事,谢谢。
Beta Was this translation helpful? Give feedback.
All reactions