我有这段代码:
angular.module('headroom', []).directive('headroom', function($timeout) {
return {
restrict: 'EA',
scope: {
tolerance: '=',
offset: '=',
classes: '=',
target: '@',
onPin: '&',
onUnpin: '&'
},
link: function(scope, element) {
var options = {};
angular.forEach(Headroom.options, function(value, key) {
options[key] = scope[key] || Headroom.options[key];
});
var headroom = new Headroom(element[0], options);
headroom.init();
scope.$on('destroy', function() {
headroom.destroy();
});
}
};
});
如何从我的控制器访问Headroom原型(var headroom)?
答案 0 :(得分:0)
您需要按以下方式扩展选项
var options = {
onPin: function () {
console.log('Pin');
},
onUnpin: function () {
console.log('Un Pin');
}
};
来自你所拥有的
var options = {};
当它遍历选项时,它只有类,容差和偏移的键。添加它将为您提供所需的回调。