我试图在表格中实现响应式输入宽度,但import { forwardRef, ViewChild, Input, Output, EventEmitter, ElementRef, AfterViewInit, OnDestroy, Component} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import * as $ from "jquery";
import 'jqueryui';
const DATE_PICKER_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => DatePickerComponent),
multi: true
};
@Component({
selector: 'qnet-datepicker',
template: `<input #input type="text">`,
providers: [DATE_PICKER_VALUE_ACCESSOR]
})
export class DatePickerComponent implements AfterViewInit, ControlValueAccessor, OnDestroy {
private onTouched = () => {};
private onChange: (date: Date) => void = () => {};
@Input() date: Date;
@Input() options: any = {};
@Output() dateChange = new EventEmitter();
@ViewChild('input') input: ElementRef;
constructor() {
this.date = new Date();
}
writeValue(date: Date) {
if(!date) {
return;
}
this.date = date;
$(this.input.nativeElement).datepicker('setDate', this.date)
}
registerOnChange(fn: any) {
this.onChange = fn;
}
registerOnTouched(fn: any) {
this.onTouched = fn;
}
ngAfterViewInit() {
$(this.input.nativeElement).datepicker(Object.assign({}, this.options, {
onSelect: (dateStr: string) => {
// this.date = $(this.input.nativeElement).datepicker('getDate');
// this.onChange(this.date);
this.onTouched();
this.dateChange.next(this.date);
}
}))
console.log('date is ' + this.date)
$(this.input.nativeElement).datepicker('setDate', this.date)
}
ngOnDestroy() {
$(this.input.nativeElement).datepicker('destroy');
}
}
在表格中不起作用。例如:
<qnet-datepicker #startDate [date]="startDate" (dateChange)="updateStart(startDate.date, startTime.value)"></qnet-datepicker>
&#13;
input {max-width:100%;}
&#13;
答案 0 :(得分:0)
max-width属性不适用于百分比。请你使用width属性来实现你想要做的事情。
只需尝试输入即可,它应该有效 -
width: CALC(100%);
max-width: 80px; (or whatever you want)
检查它是否有效!