Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit b444397

Browse files
committed
Add sample of inlining of templates & styles
1 parent fbbe7e7 commit b444397

File tree

7 files changed

+66
-4
lines changed

7 files changed

+66
-4
lines changed

src/angular-library-starter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// Public classes.
2+
export { SumComponent } from './components/sum.component';
23
export { SumService } from './services/sum.service';
34
export { ArithmeticModule } from './modules/arithmetic.module';

src/components/sum.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="sum">
2+
<p>Somma</p>
3+
<p>{{ sum }}</p>
4+
</div>

src/components/sum.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.sum {
2+
p {
3+
color: red;
4+
}
5+
}

src/components/sum.component.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { SumService } from '../services/sum.service';
3+
4+
@Component({
5+
selector: 'cmp-sum',
6+
templateUrl: './sum.component.html',
7+
styleUrls: ['./sum.component.scss']
8+
})
9+
export class SumComponent implements OnInit {
10+
11+
sum: number;
12+
13+
constructor(private sumService: SumService) { }
14+
15+
ngOnInit(): void {
16+
this.sumService.calculate(45, 78, 90, 674);
17+
this.sum = this.sumService.sum;
18+
}
19+
20+
}

src/modules/arithmetic.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { NgModule, ModuleWithProviders } from '@angular/core';
22

33
import { SumService } from '../services/sum.service';
4+
import { SumComponent } from '../components/sum.component';
45

56
@NgModule({
67
declarations: [
78
// Pipes.
89
// Directives.
910
// Components.
11+
SumComponent
1012
],
1113
exports: [
1214
// Pipes.
1315
// Directives.
1416
// Components.
17+
SumComponent
1518
]
1619
})
1720
// Consider registering providers using a forRoot() method
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { SumComponent, SumService } from '../../src/angular-library-starter';
2+
3+
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
4+
5+
describe('Component: SumComponent', () => {
6+
7+
let fixture: ComponentFixture<SumComponent>;
8+
let comp: SumComponent;
9+
10+
beforeEach(async () => {
11+
TestBed.configureTestingModule({
12+
imports: [],
13+
providers: [
14+
SumService
15+
],
16+
declarations: [SumComponent]
17+
}).compileComponents();
18+
19+
fixture = TestBed.createComponent(SumComponent);
20+
comp = fixture.componentInstance;
21+
});
22+
23+
it('should render the sum', (() => {
24+
fixture.detectChanges();
25+
26+
expect(fixture.debugElement.nativeElement.textContent).toContain('887');
27+
}));
28+
29+
});

tslint.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
true,
88
"attribute",
99
[
10-
"dir-prefix1",
11-
"dir-prefix2"
10+
"dir",
11+
"dir"
1212
],
1313
"camelCase"
1414
],
1515
"component-selector": [
1616
true,
1717
"element",
1818
[
19-
"cmp-prefix1",
20-
"cmp-prefix2"
19+
"cmp",
20+
"cmp"
2121
],
2222
"kebab-case"
2323
]

0 commit comments

Comments
 (0)