|
| 1 | +// **DO NOT CHANGE**. The analyzer looks for this _specific name_. |
| 2 | +library angular.meta; |
| 3 | + |
| 4 | +// Work in progress. |
| 5 | +// |
| 6 | +// - https://github.com/dart-lang/angular/issues/930 |
| 7 | +// - https://github.com/dart-lang/sdk/issues/33353 |
| 8 | +// |
| 9 | +// Once this is enabled we will export it from `angular.dart`. |
| 10 | + |
| 11 | +/// Used to annotate a class, field, or method that is public for template use. |
| 12 | +/// |
| 13 | +/// An annotated element may be referenced in the _same_ Dart library, or in |
| 14 | +/// any Dart source file whose filename ends in `.template.dart`. Tools, such as |
| 15 | +/// the analyzer can provide feedback if the annotated element is used anywhere |
| 16 | +/// else. |
| 17 | +/// |
| 18 | +/// This annotation is intended to be used to identify what elements of a class |
| 19 | +/// or library are only public (not private) because they represent state that |
| 20 | +/// will be referenced in the template HTML of an AngularDart component. For |
| 21 | +/// example: |
| 22 | +/// |
| 23 | +/// ```dart |
| 24 | +/// // my_component.dart |
| 25 | +/// import 'package:angular/angular.dart'; |
| 26 | +/// |
| 27 | +/// @Component( |
| 28 | +/// selector: 'my-comp', |
| 29 | +/// template: 'Hello {{fullName}}!', |
| 30 | +/// ) |
| 31 | +/// class MyComponent { |
| 32 | +/// @Input() |
| 33 | +/// String firstName; |
| 34 | +/// |
| 35 | +/// @Input() |
| 36 | +/// String lastName; |
| 37 | +/// |
| 38 | +/// @visibleForTemplate |
| 39 | +/// String get fullName => '$firstName $lastName'; |
| 40 | +/// } |
| 41 | +/// ``` |
| 42 | +/// |
| 43 | +/// ... `fullName` is a computed field that only exists for use in a `template` |
| 44 | +/// and is not intended to be part of the public API of the component. Another |
| 45 | +/// library attempting to access `fullName` would trigger a diagnostic: |
| 46 | +/// |
| 47 | +/// ```dart |
| 48 | +/// // other_lib.dart |
| 49 | +/// import 'my_component.dart'; |
| 50 | +/// |
| 51 | +/// void example(MyComponent comp) { |
| 52 | +/// // LINT |
| 53 | +/// print(comp.fullName); |
| 54 | +/// } |
| 55 | +/// ``` |
| 56 | +const visibleForTemplate = const _VisibleForTemplate(); |
| 57 | + |
| 58 | +class _VisibleForTemplate { |
| 59 | + const _VisibleForTemplate(); |
| 60 | +} |
0 commit comments