Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit 0153bfb

Browse files
committed
docs(template-syntax/dart): enhancements to example code
Enhancements to `NgStyle` section in support of its API docs. - Add feature supporting interactive update of a paragraph’s style. - Add full type declarations. - Replace bogus implementation of `getStyles()`.
1 parent 177161a commit 0153bfb

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

public/docs/_examples/template-syntax/dart/lib/app_component.dart

+22-4
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ class AppComponent implements OnInit, AfterViewInit {
126126
}
127127

128128
String getStyles(Element el) {
129-
var showStyles = setStyles();
130-
return JSON.encode(showStyles);
129+
final style = el.style;
130+
final Map styles = <String, String>{};
131+
for(var i = 0; i < style.length; i++) {
132+
styles[style.item(i)] = style.getPropertyValue(style.item(i));
133+
}
134+
return JSON.encode(styles);
131135
}
132136

133137
Map<String, bool> _previousClasses = {};
@@ -149,15 +153,29 @@ class AppComponent implements OnInit, AfterViewInit {
149153
// #enddocregion setClasses
150154

151155
// #docregion setStyles
152-
Map setStyles() {
153-
return {
156+
Map<String, String> setStyles() {
157+
return <String, String>{
154158
'font-style': canSave ? 'italic' : 'normal', // italic
155159
'font-weight': !isUnchanged ? 'bold' : 'normal', // normal
156160
'font-size': isSpecial ? '24px' : '8px' // 24px
157161
};
158162
}
159163
// #enddocregion setStyles
160164

165+
// #docregion NgStyle
166+
bool isItalic = false;
167+
bool isBold = false;
168+
String fontSize = 'large';
169+
170+
Map<String,String> setStyle() {
171+
return {
172+
'font-style': isItalic ? 'italic' : 'normal',
173+
'font-weight': isBold ? 'bold' : 'normal',
174+
'font-size': fontSize
175+
};
176+
}
177+
// #enddocregion NgStyle
178+
161179
String title = 'Template Syntax';
162180
String toeChoice;
163181
String toeChooser(Element picker) {

public/docs/_examples/template-syntax/dart/lib/app_component.html

+12
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,18 @@ <h3>Result: {{currentHero.firstName}}</h3>
409409
<!-- NgStyle binding -->
410410
<hr><h2 id="ngStyle">NgStyle Binding</h2>
411411

412+
<!-- #docregion NgStyle -->
413+
<div>
414+
<p [ngStyle]="setStyle()" #styleP>Change style of this text!</p>
415+
416+
<label>Italic: <input type="checkbox" [(ngModel)]="isItalic"></label> |
417+
<label>Bold: <input type="checkbox" [(ngModel)]="isBold"></label> |
418+
<label>Size: <input type="text" [(ngModel)]="fontSize"></label>
419+
420+
<p>Style set to: <code>'{{styleP.style.cssText}}'</code></p>
421+
</div>
422+
<!-- #enddocregion NgStyle -->
423+
412424
<!-- #docregion NgStyle-1 -->
413425
<div [style.font-size]="isSpecial ? 'x-large' : 'smaller'" >
414426
This div is x-large.

0 commit comments

Comments
 (0)