使用jQuery插件的基本过程通常是为它创建一个指令。回调函数link
内部初始化插件。在这里你可以访问元素作为jQuery或jQ-lite对象,角度范围和插件回调。请参阅有关第三方代码中进行更改范围时uing $.apply()
重要意见
样本HTML:
<input my-picker type="text"/>
Basic脚本大纲:
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)
}
}
})
您可以通过添加其他属性,以增强该指令标记,然后使用属性来设置各种插件选项。
不可能触发,因为当使用脚本更改值时,浏览器无法识别更改事件 – charlietfl