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

Commit e2ed092

Browse files
committed
refactor($compile): moving controller setup into its own method
1 parent 0196730 commit e2ed092

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

src/ng/compile.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -1878,6 +1878,38 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18781878
}
18791879
}
18801880

1881+
function setupControllers(scope, isolateScope, $element, attrs, transcludeFn, elementControllers) {
1882+
// For directives with element transclusion the element is a comment,
1883+
// but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1884+
// clean up (http://bugs.jquery.com/ticket/8335).
1885+
// Instead, we save the controllers for the element in a local hash and attach to .data
1886+
// later, once we have the actual element.
1887+
var controllerData = !hasElementTranscludeDirective && $element.data();
1888+
1889+
for (var directiveName in controllerDirectives) {
1890+
var directive = controllerDirectives[directiveName];
1891+
1892+
var locals = {
1893+
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
1894+
$element: $element,
1895+
$attrs: attrs,
1896+
$transclude: transcludeFn
1897+
};
1898+
1899+
var directiveController = directive.controller;
1900+
if (directiveController === '@') {
1901+
directiveController = attrs[directive.name];
1902+
}
1903+
1904+
var controllerInstance = $controller(directiveController, locals, true, directive.controllerAs);
1905+
1906+
elementControllers[directive.name] = controllerInstance;
1907+
if (controllerData) {
1908+
controllerData['$' + directive.name + 'Controller'] = controllerInstance.instance;
1909+
}
1910+
}
1911+
}
1912+
18811913

18821914
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn,
18831915
thisLinkFn) {
@@ -1904,37 +1936,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19041936
}
19051937

19061938
if (controllerDirectives) {
1907-
elementControllers = createMap();
1908-
1909-
// For directives with element transclusion the element is a comment,
1910-
// but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1911-
// clean up (http://bugs.jquery.com/ticket/8335).
1912-
// Instead, we save the controllers for the element in a local hash and attach to .data
1913-
// later, once we have the actual element.
1914-
var controllerData = !hasElementTranscludeDirective && $element.data();
1915-
1916-
for (var directiveName in controllerDirectives) {
1917-
var directive = controllerDirectives[directiveName];
1918-
1919-
var locals = {
1920-
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
1921-
$element: $element,
1922-
$attrs: attrs,
1923-
$transclude: transcludeFn
1924-
};
1925-
1926-
var directiveController = directive.controller;
1927-
if (directiveController === '@') {
1928-
directiveController = attrs[directive.name];
1929-
}
1930-
1931-
var controllerInstance = $controller(directiveController, locals, true, directive.controllerAs);
1932-
1933-
elementControllers[directive.name] = controllerInstance;
1934-
if (controllerData) {
1935-
controllerData['$' + directive.name + 'Controller'] = controllerInstance.instance;
1936-
}
1937-
}
1939+
setupControllers(scope, isolateScope, $element, attrs, transcludeFn, elementControllers = createMap());
19381940
}
19391941

19401942
if (newIsolateScopeDirective) {

0 commit comments

Comments
 (0)