I'm trying to build a "Team Member" page from JSON data.
I can create the page with basic things like firstName, lastName, position.
Each team member has their own page with a little more information
What I cant figure out is how to include the team members url to my [routerLink].
My router link would look like this which I have setup in my routes
<a [routerLink]="['./glenn']">
And this is how I'm attempting to use it
<div class="team-members" *ngFor="let teammember of teammembers" >
<div class="clearfix">
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-6 team-member member-item" style="cursor: pointer;">
<a [routerLink]="['./"{{teammember.firstName}}"']">
<div class="member-pic-holder">
<img alt="" src='{{teammember.photo}}' />
<div class="member-overlay"></div>
</div>
<h4>{{teammember.firstName}}<br/>{{teammember.lastName}} <span class="fa fa-arrow-right"></span></h4>
<p class="company-position">{{teammember.position}}</p>
</a>
</div>
</div>
</div>
Any thoughts on this one please?
It's also breaking when I'm trying to include the team-members photo
<img alt="" src='{{teammember.photo}}' />
However one thing at a time!
Thanks
GWS
You are using the {{ foo.bar }} binding incorrectly, the {{ }} syntax allows you to do one way binding, what you want is to use regular js expressions when binding to your objects properties.
When binding to an html element attribute, you can use the [attr.{id|href|etc}] binding, in your case, for the href of the image you can use:
<img alt="" [attr.href] = 'teammember.photo' />
And for the router, simply use [routerLink] = "[teammember.firstName]" (not sure why you need the ./, if you do need it, you could append it using a getter on your team member class, as shown bellow.
For your routes, you could do something along the lines of:
Team Member Class
export class TeamMember {
// ...properties and constructor
private memberUrl: string = "foobar"
get MemberRoute(){
return `./${this.memberUrl}`;
}
}
Template:
<div class="team-members" *ngFor="let teammember of teammembers" >
<div class="clearfix">
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-6 team-member member-item" style="cursor: pointer;">
<a [routerLink]="[teammember.MemberRoute']">
<div class="member-pic-holder">
<img [attr.href] = 'teammember.photo' />
<div class="member-overlay"></div>
</div>
<h4>{{teammember.firstName}}<br/>{{teammember.lastName}} <span class="fa fa-arrow-right"></span></h4>
<p class="company-position">{{teammember.position}}</p>
</a>
</div>
</div>
</div>
Hope this helps!
can you try like this:
['./',teammember.firstName]
for img use
<img alt="" [src]="teammember.photo" />
Related
I am using p-picklist and I want to edit target list span data used for displaying the value.
I am using the source code: https://primefaces.org/primeng/showcase/#/picklist
How can I make product name editable in the target list.
<p-pickList
[source]="sourceProducts"
[target]="targetProducts"
sourceHeader="Available"
targetHeader="Selected"
[dragdrop]="true"
[responsive]="true"
[sourceStyle]="{'height':'30rem'}"
[targetStyle]="{'height':'30rem'}"
filterBy="name"
sourceFilterPlaceholder="Search by name"
targetFilterPlaceholder="Search by name"
>
<ng-template let-product pTemplate="item">
<div class="product-item">
<div class="image-container">
<img
src="assets/showcase/images/demo/product/{{product.image}}"
[alt]="product.name"
class="product-image"
/>
</div>
<div class="product-list-detail">
<h5 class="p-mb-2">{{product.name}}</h5>
<i class="pi pi-tag product-category-icon"></i>
<span class="product-category">{{product.category}}</span>
</div>
<div class="product-list-action">
<h6 class="p-mb-2">${{product.price}}</h6>
<span
[class]="'product-badge status-' + product.inventoryStatus.toLowerCase()"
>{{product.inventoryStatus}}</span
>
</div>
</div>
</ng-template>
</p-pickList>
Turning the <h5 class="p-mb-2">{{product.name}}</h5> into an input with [(ngModel)]="product.name" seem to work.
In order to check if the templated item is listed under target and not under source, you can check the element's position on the DOM; if it is inside .p-picklist-target, show the input, else show h5.
StackBlitz
with a custom module, I have added the two fields header and footer to every res.company object. These are fields of the type binary.
I now want to display them in my document layout in qweb.
Unfortunately, odoo tells me
'base.document.layout' object has no attribute 'header'
This is what my layout looks like
<?xml version="1.0"?>
<t t-name="web.external_layout_boxed">
<div t-attf-class="header o_company_#{company.id}_layout" t-att-style="report_header_style">
<div class="o_boxed_header">
<div class="row mb8">
<div class="col-6">
<!--HERE--> <img t-if="company.logo" t-att-src="image_data_uri(company.header)" alt="brief_header"/>
</div>
<div class="col-6 text-right mb4">
<h4 class="mt0" t-field="company.report_header"/>
<div name="company_address" class="float-right mb4">
<span class="company_address" t-field="company.partner_id" t-options="{"widget": "contact", "fields": ["address", "name"], "no_marker": true}"/>
</div>
</div>
</div>
</div>
</div>
<div t-attf-class="article o_report_layout_boxed o_company_#{company.id}_layout" t-att-data-oe-model="o and o._name" t-att-data-oe-id="o and o.id" t-att-data-oe-lang="o and o.env.context.get('lang')">
<div class="pt-5">
<t t-call="web.address_layout"/>
</div>
<t t-raw="0"/>
</div>
<img t-if="company.logo" t-att-src="image_data_uri(company.footer)" alt="brief_footer"/>
</t>
as you can see I am trying to access the header with company.header
the pictures appended show you that the fields exist on the type.
What am I doing wrong? How can I correctly display the uploaded images in the external_layout_boxed?
When rendering the document, the company variable is set to wizard object not to the user company. Odoo will try to access header and footer in base.document.layout model.
To fix that issue, alter the document layout model like following:
class BaseDocumentLayout(models.TransientModel):
_inherit = 'base.document.layout'
header = fields.Binary(related="company_id.header")
footer = fields.Binary(related="company_id.footer")
You can find an example in l10n_de module where they created a new report layout and altered base.document.layout to use new fields like street, city or bank_ids
I want to use NG-ZORRO-andt pagination in the Html page, it's showing in my browser but how do I link the data from the api with the pagination?
This is my Html code
<div class="col-md-6 col-lg-4 col-xl-3" *ngFor="let course of peopleHome"> //I want to paginate this data
<div class="card-blog">
<a href="#">
<img src="../assets/images/image10.jpg" alt="" class="img-blog" />
</a>
<div class="card">
<a href="#">
<h4 class="title-blog">{{course.people_title}}</h4>
</a>
</div>
</div>
</div>
<nz-pagination [nzPageIndex]="1" [nzTotal]="peopleHome.length" [nzPageSize]="10"> </nz-pagination>
</div>
So please how can i link my response to nz-pagination?
You are using nz-pagination without any work with your array. How an array should understand that you want to get a part of it? There is two option to paginate your array:
Use nz-table
Use (nzPageIndexChange) and (nzPageSizeChange) methods of nz-pagination to filter your array
I'm getting this error in console, Cannot read property '0' of undefined but still I'm getting the result as expected.
This is my HTML code
<div class="col-md-3">
<div class="slider-product">
<a href="#">
<img src="{{featureProducts[0].img_path}}" alt="Image" style="max-width:100%;">
<span class="tag">{{featureProducts[0].cat_name}}</span>
<div>
<a class="title">{{featureProducts[0].name}}</a>
</div>
<div class="price">
<i class="fa fa-inr"></i> {{featureProducts[0].min_price}}
</div>
</a>
</div>
</div>
Here is the function in typescript file
getFeatureProducts(){
this.httpClient.get(this.baseUrl+`/getFeatureProducts`)
.subscribe(
(data:any[]) => {
if(data.length) {
this.featureProducts = data;
}else{
this.featureProducts = null;
}
}
)}
featureProducts is declared inside the class as
featureProducts: any;
I know there is work around to this problem, like I can use multiple variables as below
in typescript
imgpath0 = this.featureProducts[0].imgPath;
And using this variable in html directly as
{{imgPath0}}
But this is not a better approach as I have lot of properties to be displayed in html and I cannot declare as many variables in ts.
Note: I don't want to loop using 'for' in html. Instead I need to fetch the properties as we usually do in JSON.
You can use *ngIf="featureProducts && featureProducts[0]" and prevent rendering the div until featureProducts object gets populated.
<div class="slider-product" *ngIf="featureProducts && featureProducts[0]">
<a href="#">
<img src="{{featureProducts[0].img_path}}" alt="Image" style="max-width:100%;">
<span class="tag">{{featureProducts[0].cat_name}}</span>
<div>
<a class="title">{{featureProducts[0].name}}</a>
</div>
<div class="price">
<i class="fa fa-inr"></i> {{featureProducts[0].min_price}}
</div>
</a>
</div>
I have an array of the following class:
export class Ref {
constructor(
private id: number,
private image: string,
private title: string,
private descript: string,
private url: string,
private urlType: string,
) { }
}
and in my html I call it like this:
<div class="row">
<div class="col-sm-3" *ngFor="let r of ref">
<a [href]="r.url" [target]="r.urlType" class="reforms-1">
<img class="refimg" [src]="r.image" alt="">
<span class="reftitle"><h4>{{r.title}}</h4></span>
<span class="refline"> </span>
<p>
{{r.description}}
</p>
</a>
</div>
</div>
Everything works well except <a>. I have an url type which sometimes is _blank sometimes _self etc. So, sometimes it will be router link and sometimes external link (that's why I'm not using routerLink).
When I click on the link it's doing full post back in new page when it's _blank and that's ok but when it's _self browser is doing post back in the same page.
How can I rectify this mistake?
Use attribute data binding:
<a [href]="r.url" [attr.data-target]="r.urlType" class="reforms-1">
This should work.
You need to use a routerLink. A plain <a href="..."> is handled by the browser, not by Angular.
<div class="row">
<div class="col-sm-3" *ngFor="let r of ref">
<a *ngIf="r.urlType !== 'routerLink'" [href]="r.url" [target]="r.urlType" class="reforms-1">
<img class="refimg" [src]="r.image" alt="">
<span class="reftitle"><h4>{{r.title}}</h4></span>
<span class="refline"> </span>
<p>
{{r.description}}
</p>
</a>
<a *ngIf="r.urlType == 'routerLink'" [routerLink]="r.url"> ... </a>
</div>
</div>