jQuery 플러그인을 사용하기위한 기본 절차는 일반적으로 이에 대한 지시문을 작성하는 것입니다. link
콜백 안에서 플러그인을 초기화합니다. 여기에서 jQuery 또는 jQ-Lite 오브젝트, 각도 범위 및 플러그인 콜백으로 요소에 액세스 할 수 있습니다. 타사 코드 내에서 범위를 변경할 때 $.apply()
을 uing에 대한 중요한 주석을 참조하십시오
샘플 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