Closed hnguyenec closed 8 years ago
lrStickyheader supports the standard packagings: AMD, Commonjs and default to a global variable if none of it is used.
So the easiest would be to wrap the global in a factory so it becomes injectable by angular:
// assuming the script lrStickyHeader.js has already run (so the global variable exists)
angular.module('myModule', ['myDependencies'])
.factory('lrStickyHeader', function(){
return function(table){
lrStickyHeader(table);
}
})
so now you can get it injected
Thanks lorenzofox3 Will give it a try
I have defined a factory as above then create a directive angular .module('core') .directive('stStickyHeader', stStickyHeader);
stStickyHeader.$inject = ['$window', 'lrStickyHeader'];
function stStickyHeader($window, lrStickyHeader){
var DDO = {
require: '^?stTable',
link: stStickyHeaderLink
};
function stStickyHeaderLink(scope, element, attrs, tableController){
var stickyHeader = lrStickyHeader(element[0]);
scope.$on('$destroy', function () {
stickyHeader.clean();
});
scope.$watch(function () {
return tableController.tableState();
}, function () {
$window.scrollTo(0, lrStickyHeader.treshold);
}, true);
}
return DDO;
}
And my table html "table st-table="list" st-safe-src="safeList" class="table table-striped" st-sticky-header"
However, lrStickyHeader(element[0]) always return 'Undefined' Do you have any idea ?
lorenzofox3 , why not add this to your documentation? give an example on the document so that we can use it.
require: '^?stTable' should be require: '?^stTable'
see code source of stStickyHeader and example on readme
I am current struggling how to inject lrStickyHeader to angular app to be able to call: lrStickyHeader(element[0]) as from example as in strict DI mode, we need explicitly specify lrStickyHeader as a dependency