每次单击日历视图的上一个或下一个按钮时,我都需要从 rest-API 重新加载 vm.events。
如何覆盖这些按钮调用的方法。作为替代方法,如何实现自定义方法?
提前感谢!
阿希姆
您
不需要覆盖angular-bootstrap-calendar
中的指令,您只需在按钮上添加一个ng-click
即可。
您的观点:
<button mwl-date-modifier date="viewDate" increment="calendarView" ng-click="dateChange()">
Next
</button>
您的控制器将如下所示:
$scope.viewDate = new Date();
$scope.dateChange = function () {
var self = this;
YourService.getEvents({
month: this.viewDate.getMonth(), // You may need to add +1 depending of how your API was build
year: this.viewDate.getFullYear()
}, function (response) {
self.events = response;
})
};
您可以对increment
和decrment
使用相同的方法
如果你不想做var self = this;
,你也可以使用 ES6 中的数组函数,你的代码将是这样的:
...
}, (response) => { // Arrow function here
this.events = response;
})
...
OBS:我在我的服务中使用了ngResource,所以你的代码可能会改变一点。