You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...
import { DiscountDisplayComponent } from './discount-display.component';
import { DiscountEditorComponent } from './discount-editor.component';
import { DiscountService } from './discount.service';
@NgModule({
...
declarations: [
...
DiscountDisplayComponent,
DiscountEditorComponent
],
providers: [
...
DiscountService
]
})
export class AppModule {}
Usage
app.component.html
<!-- synchronized with the below -->
<discountEditor></discountEditor>
<discountDisplay></discountDisplay>
...
<!-- synchronized with the above -->
<discountEditor></discountEditor>
<discountDisplay></discountDisplay>
Pipe using the service
import { Pipe } from '@angular/core';
import { DiscountService } from './discount.service';
@Pipe({
name: 'discount',
pure: false
})
export class PaDiscountPipe {
constructor(private discount: DiscountService) {}
transform(price: number): number {
return this.discount.applyDiscount(price);
}
}
<ul>
<li *ngFor="let book of books; let i = index; let last = last"
[class.text-danger]="last">
{{ i + 1 }}. {{ book.title }} - {{ book.price | discount }}
</li>
</ul>