mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
chore(ng:view): simplify, by taking advantage of new compiler features
This commit is contained in:
parent
21c725f1a1
commit
f6fb31e8ad
1 changed files with 26 additions and 31 deletions
|
|
@ -540,42 +540,37 @@ var ngNonBindableDirective = valueFn({ terminal: true });
|
|||
var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$compile',
|
||||
function($http, $templateCache, $route, $anchorScroll, $compile) {
|
||||
return {
|
||||
compile: function(element, attr) {
|
||||
if (!element[0]['ng:compiled']) {
|
||||
element[0]['ng:compiled'] = true;
|
||||
terminal: true,
|
||||
link: function(scope, element) {
|
||||
var changeCounter = 0;
|
||||
|
||||
return function(scope, element, attrs) {
|
||||
var changeCounter = 0;
|
||||
scope.$on('$afterRouteChange', function() {
|
||||
changeCounter++;
|
||||
});
|
||||
|
||||
scope.$on('$afterRouteChange', function() {
|
||||
changeCounter++;
|
||||
});
|
||||
scope.$watch(function() {return changeCounter;}, function(newChangeCounter) {
|
||||
var template = $route.current && $route.current.template;
|
||||
|
||||
scope.$watch(function() {return changeCounter;}, function(newChangeCounter) {
|
||||
var template = $route.current && $route.current.template;
|
||||
function clearContent() {
|
||||
// ignore callback if another route change occured since
|
||||
if (newChangeCounter == changeCounter) {
|
||||
element.html('');
|
||||
}
|
||||
}
|
||||
|
||||
function clearContent() {
|
||||
// ignore callback if another route change occured since
|
||||
if (newChangeCounter == changeCounter) {
|
||||
element.html('');
|
||||
}
|
||||
if (template) {
|
||||
$http.get(template, {cache: $templateCache}).success(function(response) {
|
||||
// ignore callback if another route change occured since
|
||||
if (newChangeCounter == changeCounter) {
|
||||
element.html(response);
|
||||
$compile(element.contents())($route.current.scope);
|
||||
$anchorScroll();
|
||||
}
|
||||
|
||||
if (template) {
|
||||
$http.get(template, {cache: $templateCache}).success(function(response) {
|
||||
// ignore callback if another route change occured since
|
||||
if (newChangeCounter == changeCounter) {
|
||||
element.html(response);
|
||||
$compile(element)($route.current.scope);
|
||||
$anchorScroll();
|
||||
}
|
||||
}).error(clearContent);
|
||||
} else {
|
||||
clearContent();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
}).error(clearContent);
|
||||
} else {
|
||||
clearContent();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}];
|
||||
|
|
|
|||
Loading…
Reference in a new issue