Ad
Change Md-card-title From App.component.html When Card Has Its Own Component
<app-card></app-card>
is in my app.component.html and displays the card component
<md-card class="card" style="box-shadow: none;">
<md-card-header>
<md-card-title style="font-size:x-large;">
</md-card-title>
</md-card-header>
<md-card-content>
<p class="flow-text">
{{placeholder}} </p>
</md-card-content>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</md-card-actions>
above is my card
I want to change the card title (ultimately also the content) without having the clutter of the card html code in my app.component.html . I cant seem to figure out how I pass a string from my card.component.ts into my cards when having more than one string.
- Card should have title {{title1}} 2.nd card should have title {{title2}}
How do I use ngFor to repeat the number of cards displayed to the count of the strings in an array and therefore pass the string at which the index is into the card title?
Ad
Answer
You can have a component called card.component with:
import { Component } from '@angular/core';
@Component({
selector: 'my-card',
template:`
<md-card class="card" style="box-shadow: none;">
<md-card-header>
<md-card-title style="font-size:x-large;">
{{title}}
</md-card-title>
</md-card-header>
<md-card-content>
<p class="flow-text">
{{placeholder}} </p>
</md-card-content>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</md-card-actions>
`
})
export class CardComponent{
@Input() placeholder: string;
@Input() title: string;
}
And finally to use it you just need:
<my-card [title] = "title" [placeholder] = "placeholder"></my-card>
Ad
source: stackoverflow.com
Related Questions
- → Make a Laravel collection into angular array (octobercms)
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → Angularjs not working inside laravel form
- → Analysis of Flux implementations
- → how to write react component to construct HTML DOM
- → angular ng-repeat and images in a row
- → Conditional BG Color on AngularJS
- → Should I 'use strict' for every single javascript function I write?
- → getting the correct record in Angular with a json feed and passed data
- → "Undefined is not a function" at .toBe fucntion
- → angularjs data binding issue
- → Angular / JavaScript auto hydrate an instance
- → Convert generic text string in json object into valid url using Angular
Ad