Finally fixed disappearing headers from dynamic columns.

Bind-once optimizations.
This commit is contained in:
Gunther Brunner
2014-06-23 14:32:12 +09:00
parent 958cfd090e
commit 692582ce3d
7 changed files with 99 additions and 35 deletions

View File

@@ -0,0 +1,16 @@
module.exports = function ($http, $templateCache, $compile) {
var cache = {}
return function (src, scope, cloneAttachFn) {
var compileFn = cache[src]
if (compileFn) {
compileFn(scope, cloneAttachFn)
} else {
$http.get(src, { cache: $templateCache }).success(function (response) {
var responseContents = angular.element('<div></div>').html(response).contents()
compileFn = cache[src] = $compile(responseContents)
compileFn(scope, cloneAttachFn)
})
}
}
}

View File

@@ -0,0 +1,17 @@
module.exports = function includeCachedDirective(CompileCacheService) {
return {
restrict: 'ECA',
terminal: true,
compile: function (element, attrs) {
var srcExp = attrs.ngIncludeCached || attrs.src
return function (scope, element) {
var src = scope.$eval(srcExp)
var newScope = scope.$new()
CompileCacheService(src, newScope, function (compiledElm) {
element.append(compiledElm)
})
}
}
}
}

View File

@@ -0,0 +1,23 @@
describe('includeCached', function () {
beforeEach(module('stf.include-cached'));
var scope, compile;
beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
compile = $compile;
}));
it('should ...', function () {
/*
To test your directive, you need to create some html that would use your directive,
send that through compile() then compare the results.
var element = compile('<div include-cached name="name">hi</div>')(scope);
expect(element.text()).toBe('hello, world');
*/
});
});

View File

@@ -0,0 +1,5 @@
module.exports = angular.module('stf.include-cached', [
])
.factory('CompileCacheService', require('./compile-cache-service'))
.directive('ngIncludeCached', require('./include-cached-directive'))