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

Commit b55b14b

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

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

src/ng/compile.js

+34-33
Original file line numberDiff line numberDiff line change
@@ -1830,10 +1830,41 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18301830
}
18311831
}
18321832

1833+
function setupControllers(scope, isolateScope, $element, attrs, transcludeFn, elementControllers) {
1834+
// For directives with element transclusion the element is a comment,
1835+
// but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1836+
// clean up (http://bugs.jquery.com/ticket/8335).
1837+
// Instead, we save the controllers for the element in a local hash and attach to .data
1838+
// later, once we have the actual element.
1839+
var controllerData = !hasElementTranscludeDirective && $element.data();
1840+
1841+
for (var directiveName in controllerDirectives) {
1842+
var directive = controllerDirectives[directiveName];
1843+
1844+
var locals = {
1845+
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
1846+
$element: $element,
1847+
$attrs: attrs,
1848+
$transclude: transcludeFn
1849+
};
1850+
1851+
var controller = directive.controller;
1852+
if (controller === '@') {
1853+
controller = attrs[directive.name];
1854+
}
1855+
1856+
var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
1857+
1858+
elementControllers[directive.name] = controllerInstance;
1859+
if (controllerData) {
1860+
controllerData['$' + directive.name + 'Controller'] = controllerInstance.instance;
1861+
}
1862+
}
1863+
}
1864+
18331865

18341866
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
1835-
var i, ii, linkFn, directive, controller, isolateScope, elementControllers, transcludeFn, $element,
1836-
attrs;
1867+
var i, ii, linkFn, isolateScope, elementControllers, transcludeFn, $element, attrs;
18371868

18381869
if (compileNode === linkNode) {
18391870
attrs = templateAttrs;
@@ -1855,37 +1886,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
18551886
}
18561887

18571888
if (controllerDirectives) {
1858-
elementControllers = createMap();
1859-
1860-
// For directives with element transclusion the element is a comment,
1861-
// but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1862-
// clean up (http://bugs.jquery.com/ticket/8335).
1863-
// Instead, we save the controllers for the element in a local hash and attach to .data
1864-
// later, once we have the actual element.
1865-
var controllerData = !hasElementTranscludeDirective && $element.data();
1866-
1867-
for (var directiveName in controllerDirectives) {
1868-
var directive = controllerDirectives[directiveName];
1869-
1870-
var locals = {
1871-
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
1872-
$element: $element,
1873-
$attrs: attrs,
1874-
$transclude: transcludeFn
1875-
};
1876-
1877-
var controller = directive.controller;
1878-
if (controller === '@') {
1879-
controller = attrs[directive.name];
1880-
}
1881-
1882-
var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
1883-
1884-
elementControllers[directive.name] = controllerInstance;
1885-
if (controllerData) {
1886-
controllerData['$' + directive.name + 'Controller'] = controllerInstance.instance;
1887-
}
1888-
}
1889+
setupControllers(scope, isolateScope, $element, attrs, transcludeFn, elementControllers = createMap());
18891890
}
18901891

18911892
if (newIsolateScopeDirective) {

0 commit comments

Comments
 (0)