filmov
tv
Style binding in angular 2

Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
Angular 2 Tutorial playlist
Angular 2 Text articles and slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In this video we will discuss Style binding in Angular with examples.
Setting inline styles with style binding is very similar to setting CSS classes with class binding. Please wtach Class binding video from Angular 2 tutorial before proceeding with this video.
Notice in the example below, we have set the font color of the button using the style attribute.
@Component({
selector: 'my-app',
template: `
[button style="color:red"]My Button[/button]
`
})
export class AppComponent {
}
The following example sets a single style (font-weight). If the property 'isBold' is true, then font-weight style is set to bold else normal.
@Component({
selector: 'my-app',
template: `
[button style='color:red'
[/button]
`
})
export class AppComponent {
isBold: boolean = true;
}
style property name can be written in either dash-case or camelCase. For example, font-weight style can also be written using camel case - fontWeight.
Some styles like font-size have a unit extension. To set font-size in pixels use the following syntax. This example sets font-size to 30 pixels.
@Component({
selector: 'my-app',
template: `
[button style='color:red'
[/button]
`
})
export class AppComponent {
fontSize: number = 30;
}
To set multiple inline styles use NgStyle directive
1. Notice the color style is added using the style attribute
2. ngStyle is binded to addStyles() method of the AppComponent class
3. addStyles() method returns an object with 2 key/value pairs. The key is a style name, and the value is a value for the respective style property or an expression that returns the style value.
4. let is a new type of variable declaration in JavaScript.
5. let is similar to var in some respects but allows us to avoid some of the common “gotchas” that we run into when using var.
6. The differences between let and var are beyond the scope of this video. For our example, var also works fine.
7. As TypeScript is a superset of JavaScript, it supports let
@Component({
selector: 'my-app',
template: ` [button style='color:red' [ngStyle]="addStyles()"]My Button[/button]
`
})
export class AppComponent {
isBold: boolean = true;
fontSize: number = 30;
isItalic: boolean = true;
addStyles() {
let styles = {
};
return styles;
}
}
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
Angular 2 Tutorial playlist
Angular 2 Text articles and slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In this video we will discuss Style binding in Angular with examples.
Setting inline styles with style binding is very similar to setting CSS classes with class binding. Please wtach Class binding video from Angular 2 tutorial before proceeding with this video.
Notice in the example below, we have set the font color of the button using the style attribute.
@Component({
selector: 'my-app',
template: `
[button style="color:red"]My Button[/button]
`
})
export class AppComponent {
}
The following example sets a single style (font-weight). If the property 'isBold' is true, then font-weight style is set to bold else normal.
@Component({
selector: 'my-app',
template: `
[button style='color:red'
[/button]
`
})
export class AppComponent {
isBold: boolean = true;
}
style property name can be written in either dash-case or camelCase. For example, font-weight style can also be written using camel case - fontWeight.
Some styles like font-size have a unit extension. To set font-size in pixels use the following syntax. This example sets font-size to 30 pixels.
@Component({
selector: 'my-app',
template: `
[button style='color:red'
[/button]
`
})
export class AppComponent {
fontSize: number = 30;
}
To set multiple inline styles use NgStyle directive
1. Notice the color style is added using the style attribute
2. ngStyle is binded to addStyles() method of the AppComponent class
3. addStyles() method returns an object with 2 key/value pairs. The key is a style name, and the value is a value for the respective style property or an expression that returns the style value.
4. let is a new type of variable declaration in JavaScript.
5. let is similar to var in some respects but allows us to avoid some of the common “gotchas” that we run into when using var.
6. The differences between let and var are beyond the scope of this video. For our example, var also works fine.
7. As TypeScript is a superset of JavaScript, it supports let
@Component({
selector: 'my-app',
template: ` [button style='color:red' [ngStyle]="addStyles()"]My Button[/button]
`
})
export class AppComponent {
isBold: boolean = true;
fontSize: number = 30;
isItalic: boolean = true;
addStyles() {
let styles = {
};
return styles;
}
}
Комментарии