angular.io icon indicating copy to clipboard operation
angular.io copied to clipboard

feature request: show import statement on documentation page

Open tom-schoener opened this issue 10 years ago • 6 comments

I'm submitting a feature request

It happens quite often, that I search for certain classes, interfaces, etc. to learn more about them. Then, when I decide to use one I need to know where it is located in order to create my import statement, but there is no such information. The information is present on the overview page, but that is not the most convenient way for looking it up. (see https://angular.io/docs/ts/latest/api/#!?apiType=Class).

Current behavior This affects all instances, but I use OnInit as an example. The Reference page for the class OnInit does not contain any information about its location, except for its URL: https://angular.io/docs/ts/latest/api/core/index/OnInit-class.html

Therefore the following import statement is not obvious to the user.

import { OnInit } from '@angular/core'

Expected/desired behavior There are many ways to provide this information, currently I have these two in mind.

import

location

Another possibility is to show the location directly in the header:

image

Any ideas / suggestions?

tom-schoener avatar May 27 '16 07:05 tom-schoener

The API documentation issues needs to be reported in the angular repo.

Sorry for the inconvenience.

Foxandxss avatar May 27 '16 07:05 Foxandxss

Thank you for the information. I will report it there and close this one. new issue: https://github.com/angular/angular/issues/8883

tom-schoener avatar May 27 '16 07:05 tom-schoener

Reopened as suggested by @robwormald in https://github.com/angular/angular/issues/8883 .

For the first version the implementation may look something like this in tools\api-builder\angular.io-package\templates\class.template.html.

.div(layout="row" layout-xs="column" class="row-margin ng-cloak")
  div(flex="20" flex-xs="100")
    h2(class="h2-api-docs") Import
  div(flex="80" flex-xs="100")
    code-example(format="linenums" language="js") 
      code(class="no-bg api-doc-code") import { {$ doc.name $} } from '{$ doc.moduleDoc.id | replace('/index', '') $}'

tom-schoener avatar May 29 '16 08:05 tom-schoener

@naomiblack Does the fix suggested by @TTTee viable?

wardbell avatar May 29 '16 22:05 wardbell

It would probably be quite convenient, although, to be fair, at the bottom of the page there is usually subtle footnote with import information:

exported from @angular/core/index defined in @angular/core/src/metadata/lifecycle_hooks.ts (line 81)

... which is enough to figure out that OnInit is exported by @angular/core.

dfsq avatar May 30 '16 08:05 dfsq

I love this idea.

Foxandxss avatar Jul 25 '16 13:07 Foxandxss