Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f6fb31e

Browse files
mheveryvojtajina
authored andcommittedFeb 29, 2012
chore(ng:view): simplify, by taking advantage of new compiler features
1 parent 21c725f commit f6fb31e

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed
 

‎src/widgets.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -540,42 +540,37 @@ var ngNonBindableDirective = valueFn({ terminal: true });
540540
var ngViewDirective = ['$http', '$templateCache', '$route', '$anchorScroll', '$compile',
541541
function($http, $templateCache, $route, $anchorScroll, $compile) {
542542
return {
543-
compile: function(element, attr) {
544-
if (!element[0]['ng:compiled']) {
545-
element[0]['ng:compiled'] = true;
546-
547-
return function(scope, element, attrs) {
548-
var changeCounter = 0;
543+
terminal: true,
544+
link: function(scope, element) {
545+
var changeCounter = 0;
549546

550-
scope.$on('$afterRouteChange', function() {
551-
changeCounter++;
552-
});
547+
scope.$on('$afterRouteChange', function() {
548+
changeCounter++;
549+
});
553550

554-
scope.$watch(function() {return changeCounter;}, function(newChangeCounter) {
555-
var template = $route.current && $route.current.template;
551+
scope.$watch(function() {return changeCounter;}, function(newChangeCounter) {
552+
var template = $route.current && $route.current.template;
556553

557-
function clearContent() {
558-
// ignore callback if another route change occured since
559-
if (newChangeCounter == changeCounter) {
560-
element.html('');
561-
}
562-
}
554+
function clearContent() {
555+
// ignore callback if another route change occured since
556+
if (newChangeCounter == changeCounter) {
557+
element.html('');
558+
}
559+
}
563560

564-
if (template) {
565-
$http.get(template, {cache: $templateCache}).success(function(response) {
566-
// ignore callback if another route change occured since
567-
if (newChangeCounter == changeCounter) {
568-
element.html(response);
569-
$compile(element)($route.current.scope);
570-
$anchorScroll();
571-
}
572-
}).error(clearContent);
573-
} else {
574-
clearContent();
561+
if (template) {
562+
$http.get(template, {cache: $templateCache}).success(function(response) {
563+
// ignore callback if another route change occured since
564+
if (newChangeCounter == changeCounter) {
565+
element.html(response);
566+
$compile(element.contents())($route.current.scope);
567+
$anchorScroll();
575568
}
576-
});
577-
};
578-
}
569+
}).error(clearContent);
570+
} else {
571+
clearContent();
572+
}
573+
});
579574
}
580575
};
581576
}];

0 commit comments

Comments
 (0)
This repository has been archived.