-
Notifications
You must be signed in to change notification settings - Fork 2
/
framework7.angular.hook.js
42 lines (40 loc) · 1.26 KB
/
framework7.angular.hook.js
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
36
37
38
39
40
41
42
Framework7.prototype.plugins.angular = function (app, params) {
function compile(newPage) {
try {
var $page = $(newPage);
var injector = angular.element(document).injector();
if (injector && $page ) {
var $compile = injector.invoke(function ($compile) { return $compile; });
var $timeout = injector.invoke(function ($timeout) { return $timeout; });
var $scope = injector.invoke(function ($rootScope) { return $rootScope; });
$scope = $scope.$$childHead;
$timeout(function () {
$compile($page)($scope);
});
}
} catch (e) {
console.error("Some Error Occured While Compiling The Template", e);
}
}
function removeOldPage(pageData) {
var $oldPage = $(".views .view .pages .page").not($(pageData.container));
if ($oldPage.length > 0) {
var controllerName = $oldPage.attr("ng-controller");
var $scope = angular.element('[ng-controller=' + controllerName + ']').scope();
if ($scope) {
$scope.$destroy();
$oldPage.remove();
}
}
}
return {
hooks: {
pageInit: function (pageData) {
compile(pageData.container);
},
pageAfterAnimation: function (pageData) {
removeOldPage(pageData);
}
}
}
};