Binding 如何绑定";只读“;在Aurelia的自定义元素中?

Binding 如何绑定";只读“;在Aurelia的自定义元素中?,binding,aurelia,readonly,custom-element,Binding,Aurelia,Readonly,Custom Element,我在html文件中有以下元素: <require from="_controls/time-slot-slider"></require> <time-slot-slider id="zeitraum" min="0" max="24" length="4" value="4" value.two-way="functionConfig.startTime" if.bind="functionCo

我在html文件中有以下元素:

<require from="_controls/time-slot-slider"></require>

    <time-slot-slider id="zeitraum" min="0" max="24" length="4" value="4"
                              value.two-way="functionConfig.startTime" if.bind="functionConfig.isAutomatic === true"
                              readonly.bind="!mayFunctionTestEditTime"></time-slot-slider>
但是,readonly.bind不起作用。我试着用


@bindable readOnly:boolean
但我没有成功。如何修复它?

我认为问题在于您仅将
只读
应用于自定义元素:

<time-slot-slider readonly.bind="!mayFunctionTestEditTime"></time-slot-slider>

给属性一个默认值也是一个好主意,请参阅答案(特别是注释)了解原因。

我这样做了。但我得到了这个警告:在您编写的
readonly
而不是
readonly
的类型“TimeSlotSlider”中找不到“readonly”。注意大写字母
O
。在您的viewmodel中将
readOnly
更改为
readOnly
,或者在您使用该组件的HTML中将
readOnly.bind
更改为
readOnly.bind
。非常感谢
import { bindable, customElement } from 'aurelia-templating'
import moment from 'moment/moment'
import Moment = moment.Moment

@customElement('time-slot-slider')
export class TimeSlotSlider {

  @bindable public min: number = 0.0
  @bindable public max: number = 24.0
  @bindable public step: number = 0.5
  @bindable public value: number = 0.0
  @bindable public length: number = 4.0

  public get maxStart (): number {
    return this.max - this.length
  }

  public get from (): Moment {
    return TimeSlotSlider.numberToMoment(this.value)
  }
....
<time-slot-slider readonly.bind="!mayFunctionTestEditTime"></time-slot-slider>
<input type="range" readonly.bind="readonly" ... />