import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-demo-button',
template: `
输入
options: 数据类型:{{{
key: 'string(checkModel的选中值key[checked])',
text: 'string',
disabled: 'boolean',
width: 'string'
} | json}},
eg: '' || {{['test1', 'test2'] | json}}
checkModel: 数据类型{{{checked: 'boolean'} | json}}, eg: '' || '200px'
text: string, desc: '' || source中的元素(默认选中)
输出
textChangeEvent: 返回数据格式{{{title: '选中的文本'} | json}}
主动获取值text
this.autoComponent['text'], ccc在标签定义#autoComponent,在component中获取@ViewChild('autoComponent') autoComponent;
`,
styles: [`
`]
})
export class DemoCheckboxComponent implements OnInit {
/**
* checkModel的checkObj1值为双向绑定:使用方改变checked值,组件改变状态;组件改变checked值,使用方改变状态
* options的checkOptions1值为双向绑定
* 抛出事件:checkbox改变事件:checkboxChangeEvent,返回值:checkModel对应的checkObj1
*/
constructor() {
}
checkOptions1 = {
key: 'checked',
text: '性别性别性别性别性别性别性别性别性别',
disabled: true,
width: '200px'
};
checkOptions2 = {
key: 'checked',
text: '男女男女男女男女男女男女男女男女男女男女男女男女男女',
disabled: false,
width: '100px'
};
checkOptions3 = {
key: 'checked',
disabled: true,
};
checkObj1 = {
checked: true,
};
checkObj2 = {
checked: false,
};
checkObj3 = {
checked: false,
};
ngOnInit() {
setTimeout(() => {
this.checkObj1.checked = false;
}, 2000);
}
checkboxChangeEvent(ev) {
console.log(ev);
}
getCheckStatus() {
console.log(this.checkObj2);
}
}