สิ่งที่ควรรู้
ในกรณีที่จำเป็นต้องทำการ Binding Event ต่างๆให้กับสิ่งต่างๆใน Directive จำเป็นจะต้องใช้ Link
Link คือ อะไร ?
Link เป็น property ที่ใช้สำหรับทำการ Binding Event ต่างๆ และติดตามการเปลี่ยนแปลงของข้อมูลภายใน Directive
โดยใช้ฟังก์ชั่นของ jqlite ในการ binding event ต่างๆ ซึ่งมีลักษณะเหมือนกับ jQuery ทุกประการ
angular.directive('someDirective', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.click(function () {...});
element.blur(function () {...});
element.focus(function () {...});
$('input').blur(function () {...});
}
};
});
