This is potentially planned for 4.0.0, pending feedback and experimentation.
tl;dr: We'd like users to be able to refer to:
- Enums
- Top-level fields and functions
- Static members and functions of a class
... within their template (HTML).
Configuration
We'd need a way to tell the template what symbols to expect. There are several (unsatisfying) ways to solve this when it doesn't belong to the current library - for example, import with an unused import, or export. We're planning on settling on an exports: list on @Component:
import 'package:angular2/angular2.dart';
import 'some_library.dart' show topLevelField;
import 'another_library.dart' show SomeEnum;
@Component(
selector: 'comp',
// List symbols that will be accessible n
exports: const [
topLevelField,
SomeEnum,
],
)
class Comp {
@Input()
SomeEnum value;
}
<div *ngIf="value == SomeEnum.status">You are a silly monkey!</div>
<button>{{topLevelField.toUpperCase()}}</button>
Examples
Top-level fields and functions
final okButtonTitle = "OK";
@Component(...)
class Comp {}
<material-button [title]="okButtonTitle"></material-button>
Enums
enum Status {
loading,
done,
errored,
}
<div *ngIf="status == Status.loading">Loading...</div>
<div *ngIf="status == Status.done">Done!</div>
<div *ngIf="status == Status.errored">Error :(</div>
Static members and functions of a class
import 'package:intl/intl.dart';
class IntlMessages {
static final hello = Intl.message('hello');
static final cancel = Intl.message('cancel');
}
<button>{{IntlMessages.hello}}</button>
<button>{{IntlMessages.cancel}}</button>
Considerations
- It is not clear whether your own component's statics will be exported "by default"
- We should be able to support prefixed imports
/cc @MichaelRFairhurst, for considerations for the angular_analyzer_plugin.