我在我的AngularJS应用程序中使用this plugin和变量来存储开始和结束日期,无论它们何时改变。
在日期范围更改时,如何调用控制器方法来更新页面上的数据?
比如调用作用域的这个方法:
$scope.updateDataOnDateRangeChange = function(){
// here calling few services to fetch new data for the page
// for the selected date range
}如何使用此插件的ng-click或ng-change或自定义指令?
发布于 2013-10-27 11:33:52
使用jQuery插件的基本步骤通常是为它创建一个指令。在link回调中,您可以初始化插件。在这里,您可以访问作为jQuery或jQ-lite对象的元素、角度作用域和插件回调。在第三方代码中更改作用域时,请参阅有关使用$.apply()的重要注释
示例html:
<input my-picker type="text"/>基本脚本大纲:
app.directive('myPicker', function ($timeout) {
return {
link: function (scope, elem, attrs) {
$timeout(function () {
/* elem is a jQuery or jQ-lite object representing the element*/
elem.daterangepicker({
format: 'YYYY-MM-DD',
startDate: '2013-01-01',
endDate: '2013-12-31'
},
/* not overly familiar with this plugin but this callback
should allow you to set angular scopes */
function (start, end) {
/* important to do any scope changes within `$.apply()` so angular
becomes aware of changes from third party code*/
scope.$apply(function(){
/* do what you need here with angular scope
have access to plugin data as well as angular scope*/
})
});
}, 1)
}
}
})您可以通过向标记添加其他属性来增强此指令,然后使用这些属性来设置各种插件选项。
发布于 2013-10-27 04:48:32
AngularJS中存在一个ngChange directive,它应该执行您所描述的操作。
将此指令添加到日期范围输入元素。
https://stackoverflow.com/questions/19611710
复制相似问题