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

Commit eb51b02

Browse files
committed
fix(docModuleComponents): implement anchor scroll when content added
When navigating to URLs such as docs.angularjs.org/api/ng#filter, the browser was not able to navigate to the named anchor, "filter," because the anchor did not yet exist in the DOM. This fix uses the $anchorScroll service to automatically scroll to the right place when the content has been added to the page. Fixes #4703
1 parent 56d0917 commit eb51b02

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

docs/src/templates/js/docs.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -207,28 +207,29 @@ docsApp.directive.sourceEdit = function(getEmbeddedTemplate) {
207207
}
208208
};
209209

210-
docsApp.directive.docModuleComponents = ['sections', function(sections) {
210+
docsApp.directive.docModuleComponents = function() {
211211
return {
212212
template: ' <div class="component-breakdown">' +
213213
' <h2>Module Components</h2>' +
214-
' <div ng-repeat="(key, section) in components">' +
215-
' <h3 class="component-heading" id="{{ section.type }}">{{ section.title }}</h3>' +
216-
' <table class="definition-table">' +
217-
' <tr>' +
218-
' <th>Name</th>' +
219-
' <th>Description</th>' +
220-
' </tr>' +
221-
' <tr ng-repeat="component in section.components">' +
222-
' <td><a ng-href="{{ component.url }}">{{ component.shortName }}</a></td>' +
223-
' <td>{{ component.shortDescription }}</td>' +
224-
' </tr>' +
225-
' </table>' +
214+
' <div ng-repeat="(key, section) in components">' +
215+
' <h3 class="component-heading" id="{{ section.type }}">{{ section.title }}</h3>' +
216+
' <table class="definition-table">' +
217+
' <tr>' +
218+
' <th>Name</th>' +
219+
' <th>Description</th>' +
220+
' </tr>' +
221+
' <tr ng-repeat="component in section.components">' +
222+
' <td><a ng-href="{{ component.url }}">{{ component.shortName }}</a></td>' +
223+
' <td>{{ component.shortDescription }}</td>' +
224+
' </tr>' +
225+
' </table>' +
226226
' </div>' +
227227
' </div>',
228228
scope : {
229229
module : '@docModuleComponents'
230230
},
231-
controller : ['$scope', function($scope) {
231+
controller : ['$scope', '$anchorScroll', '$timeout', 'sections',
232+
function($scope, $anchorScroll, $timeout, sections) {
232233
var validTypes = ['property','function','directive','service','object','filter'];
233234
var components = {};
234235
angular.forEach(sections.api, function(item) {
@@ -239,16 +240,17 @@ docsApp.directive.docModuleComponents = ['sections', function(sections) {
239240
components[type] = components[type] || {
240241
title : type,
241242
type : type,
242-
components : []
243+
components : []
243244
};
244245
components[type].components.push(item);
245246
}
246247
}
247248
});
248249
$scope.components = components;
250+
$timeout($anchorScroll, 0, false);
249251
}]
250252
};
251-
}]
253+
};
252254

253255
docsApp.directive.docTutorialNav = function(templateMerge) {
254256
var pages = [
@@ -411,7 +413,7 @@ docsApp.serviceFactory.prepareDefaultAppModule = function() {
411413
var moduleName = 'App';
412414
return {
413415
module : moduleName,
414-
script : "angular.module('" + moduleName + "', [" +
416+
script : "angular.module('" + moduleName + "', [" +
415417
(deps.length ? "'" + deps.join("','") + "'" : "") + "]);\n\n"
416418
};
417419
};
@@ -709,7 +711,7 @@ docsApp.controller.DocsController = function($scope, $location, $window, $cookie
709711
error: 'Error Reference'
710712
};
711713

712-
populateComponentsList();
714+
populateComponentsList();
713715

714716
$scope.$watch(function docsPathWatch() {return $location.path(); }, function docsPathWatchAction(path) {
715717
// ignore non-doc links which are used in examples

0 commit comments

Comments
 (0)