Created
January 8, 2014 11:45
-
-
Save andrew-aladev/8315683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(undefined) { | |
"use strict"; | |
var COMMON_URL = "/combres.axd/angular_common_templates/1"; | |
var get_promise = function (url, $http, $injector) { | |
return $http.get(url).then(function(response) { | |
$injector.get("$compile")(response.data); | |
return response; | |
}); | |
} | |
app.view.config(["$provide", function($provide) { | |
$provide.decorator("$templateCache", ["$delegate", "$http", "$injector", function ($delegate, $http, $injector) { | |
var common_promise = null; | |
var original_get = $delegate.get; | |
$delegate.get = function (url) { | |
var index = url.indexOf("/"); | |
if (index == -1) { | |
return; | |
} | |
var group = url.substring(0, index); | |
url = url.substring(index + 1); | |
switch (group) { | |
case "common": | |
if (common_promise == null) { | |
common_promise = get_promise(COMMON_URL, $http, $injector); | |
} | |
return common_promise.then(function(response) { | |
return { | |
status : response.status, | |
data : original_get(url) | |
}; | |
}); | |
break; | |
default: | |
return; | |
break; | |
} | |
}; | |
return $delegate; | |
}]); | |
}]); | |
}) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment