primeng scheduler:用于设置组件未公开的属性的推荐方法是什么

时间:2016-12-22 12:34:18

标签: angular angular-cli primeng fullcalendar-scheduler

在查看文档时,我注意到调度程序组件不会从fullcalendar控件中公开slotLabelFormat。设置此属性的建议解决方法是什么?

感谢,

路易斯

2 个答案:

答案 0 :(得分:0)

之前我需要为另一个组件做类似的事情。结果只是因为该属性不是@Input(),甚至没有明确设置为公开,并不意味着你无法达到它。

我的做法与此相似:

@Component({
  selector: 'blah',
  template: `<custom-component #foo ></<custom-component>`
}) 
export class MyComponent {
  // You can leave it as `any` or use the actual component type if available
  @ViewChild("foo") myCustomComponent;

  ngAfterViewInit() {
    this.myCustomComponent.prop = 'value';
    // Above should work with `any`. 
    // If you are using component type, and it fails, try `any` or try:
    this.myCustomComponent["prop"] = 'value';
  }
}

它不会一直有效,也许ngAfterViewInit设置属性为时已晚。

另一种选择是继承该组件。那是在创造 class CustomComponentChild extends CustomComponent。要做到这一点,你至少需要Angular 2.3,你必须去实际的组件并复制整个@Component()装饰器,因为装饰器不会被复制或合并到Angular中的子组件。

答案 1 :(得分:0)

经过一番挖掘(即查看找到的源代码here)后,调度控件公开了一个名为schedule的属性,允许您访问jquery fullcalendar插件。有了这些信息,现在它只是使用API​​的问题:

ngAfterViewInit(){
    //this._agenda is of type Schedule
    this._agenda.schedule.fullCalendar("option", "slotLabelFormat", "HH:mm");
 }
相关问题