Created
May 24, 2019 18:08
-
-
Save jarhoads/02c81cad4e437bfe6aba75d0e8e9d0b7 to your computer and use it in GitHub Desktop.
angular directives example (component code)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { Model } from './repository.model'; | |
import { Product } from './product.model'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { | |
model: Model = new Model(); | |
targetName = 'Kayak'; | |
getClasses(): string { | |
return this.model.getProducts().length === 5 ? 'bg-success' : 'bg-warning'; | |
} | |
getClassMap(key: number): object { | |
const product = this.model.getProduct(key); | |
return { | |
'text-center bg-danger': product.name === 'Kayak', | |
'bg-info': product.price < 50 | |
}; | |
} | |
getProductByPosition(position: number): Product { | |
return this.model.getProducts()[position]; | |
} | |
getProduct(key: number): Product { | |
return this.model.getProduct(key); | |
} | |
getKey(index: number, product: Product) { | |
return product.id; | |
} | |
getProducts(): Product[] { | |
return this.model.getProducts(); | |
} | |
getProductCount(): number { | |
return this.getProducts().length; | |
} | |
getProductPrice(index: number): number { | |
return Math.floor(this.getProduct(index).price); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment