-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathangular-template-maker.js
More file actions
35 lines (27 loc) · 1.01 KB
/
angular-template-maker.js
File metadata and controls
35 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(function () {
'use strict';
angular.module('ngTemplateMaker', []);
angular
.module('ngTemplateMaker')
.factory('templateMaker', templateMaker);
templateMaker.$inject = ['$templateRequest', '$compile', '$rootScope', '$timeout', '$q'];
/* @ngInject */
function templateMaker($templateRequest, $compile, $rootScope, $timeout, $q) {
return function (url, data) {
return $templateRequest(url, false).then(function(response) {
var $scope = $rootScope.$new();
var dfd = $q.defer();
Object.keys(data).forEach(function(key) {
$scope[key] = data[key];
});
var el = angular.element('<div>' + response + '</div>');
$timeout(function() {
$compile(el)($scope);
$rootScope.$digest();
dfd.resolve(el.html());
});
return dfd.promise;
});
};
}
})();