I need to insert a bunch of blue hyperlinks inside an accordion. So when we click the title, the expansion area that appears would contain a couple lines that call some function.
I've attempted to follow the example on the Angular Material website:
https://stackblitz.com/angular/ybovddobxlj?file=app%2Fexpansion-overview-example.html
I've modified expansion-overview-example.html to the following:
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
ALL FILES
</mat-panel-title>
</mat-expansion-panel-header>
<div> <!-- To put them on separate lines -->
<mat-form-field>
<label title="File 1" onclick="openFile1()"></label> <!-- THIS LINE BREAKS THE PAGE. HELP? -->
</mat-form-field>
</div>
<div> <!-- To put them on separate lines -->
<mat-form-field>
<label title="File 2" onclick="openFile2()"></label> <!-- THIS LINE BREAKS THE PAGE. HELP? -->
</mat-form-field>
</div>
</mat-expansion-panel>
</mat-accordion>
First of all, remove the mat-form-field, it is not required if you just want a simple link in the accordion (this is actually what breaks your code).
Just add a simple p tag with a (click) event handler (it is not onclick in Angular). This should do the trick:
<div>
<p (click)="openFile1()">File 1</p>
</div>
If you want to use label instead, use it like this:
<div>
<label (click)="openFile2()">File 2</label>
</div>
It should have a value, otherwise it is not visible and you can't click it.
Here
is a stackblitz with your sample code edited to make it work.
Related
I have a material tab component (mat-tab-gruop), and i needed a search bar inside the mat-tab-header, so i added a disabled tab containing only a mat-tab-label, and placed it inside it my search bar component.
Like this:
<mat-tab-group>
<mat-tab disabled>
<ng-template mat-tab-label>
<search-bar></search-bar>
</ng-template>
</mat-tab>
</mat-tab-group>
My problem is when I press an arrow key, instead of moving the cursor between characters, the focus changes to the other headers.
That happened because angular-meterial use Keyboard interaction to move focus between tabs.
I want to disable this Keyboard interactions behaviour, and keep focus on my search bar. I know I can move back focus after losing it to another tab header, then back to the search tab-header, using binding to (selectedTabChanged) and move focus back. I want the focus to always stay on the search bar input, so I’ll be able use arrows to move between charcters.
stackbiltz Example
my code:
<mat-tab-group [selectedIndex]="'1'">
<mat-tab disabled>
<ng-template mat-tab-label>
<div>
<mat-form-field>
<input matInput class="search" [value]="searchText">
</mat-form-field>
</div>
</ng-template>
</mat-tab>
<mat-tab label="tab1">
<p>some content</p>
</mat-tab>
<mat-tab label="tab2">
<p>some content</p>
</mat-tab>
</mat-tab-group>
Stop the key events propagating from the input field to stop them reaching the tab widget
<mat-form-field>
<input matInput class="search" [value]="searchText" (keydown)="suppressKeyEvent($event)">
</mat-form-field>
and
export class TabGroupAnimationsExample {
suppressKeyEvent (event:any) {
event.stopPropagation();
}
}
https://stackblitz.com/edit/angular-xufnk7-keqvdt
Just picking up angular and had to do something similar to above, so if anyone knows of a more 'angurly' way to do it (i.e. can you write the key suppression as some kind of imported module/directive?) that'd be kewl.
I'm learning Angular. I've created a datepicker from the scratch (*why from the scratch is a different story). As you can see I've two date-picker custom component in the same widget. The code is same for both. I just copied and pasted in the same HTML file.
Here is my monthpicker.component.html
Note: dls is our own library of basic html components like textfields etc. Please Ignore that.
....
<div class="dropdown">
<span>
<dls-textbox id="upper">
<input dlsInput [ngModel]="text" placeholder="...">
</dls-textbox>
</span>
<div class="my-table-div dropdown-content">
<div class="year-div">
<input type="number" [(ngModel)]="year" value="2019" min="2018" max="2024">
</div>
<br>
<div *ngFor="..." class="my-table">
<span *ngFor="...">
<span class="month-name" (click)="onClick(x);">
{{ x.monthName }}
</span>
</span>
</div>
</div>
<!-- A TOGGLE SWITCH GOES HERE-->
<!-- THEN SAME DATE PICKER CODE I COPIED BELOW-->
<div class="dropdown">
...
</div>
But the problem is, dates selected in one calendar is reflected in the later one also.
I tried separating them by changing id and class also. But still both of them are responding together. I want them to act independently.
Please correct me.
It happens because you are binding two inputs to the same variable with the [ngModel], due to which a change in one gets reflected in the other.
Try changing the ngModel value.
<div class="year-div">
<input type="number" [(ngModel)]="year" value="2019" min="2018" max="2024">
</div>
If you enter the same value for both ngModels it will reflect the other one as well. You need to use different values for each ng-model.
Make sure you should clear the dates which you selected with another one. Make "ID" should be different in each compoenent.
I want to put a text and a checkbox side by side in a cell. The expected result likes
However the actual result is the checkbox is above the text. That means the checkbox takes one line, then the text takes the second line.
My code
<kendo-grid-checkbox-column>
<ng-template kendoGridCellTemplate let-dataItem>
<input type="checkbox" [checked]="dataItem.Discontinued">
{{dataItem.ProductName}}
</ng-template>
</kendo-grid-checkbox-column>
You could use a label:
<kendo-grid-checkbox-column>
<ng-template kendoGridCellTemplate let-dataItem>
<input type="checkbox" id="prod-name" class="k-checkbox" [checked]="dataItem.Discontinued">
<label class="k-checkbox-label" for="prod-name">{{dataItem.ProductName}}</label>
</ng-template>
</kendo-grid-checkbox-column>
To enable the kendo styles for the checkbox you should add class="k-ckeckbox" to the input.
My bad.
Actually when I created angular component, there was a css file. For some reason I copied and pasted a style into it; I didn't pay attention at it. The style is to set input element width as 95%. I delete it then it works.
I have a form consisting of two tabs.
Based on an *ngIf, I decide what kind of tabs I want to show.
- If my form is a view, I want to see both tabs with labels (both tabs have information to show the user, second tab is results).
- If my form is an add, I want to see no tabs thus no labels.
I am not willing to create two separate files as I am trying to reduce my code as much as possible.
I tried adding an ng-template that replaces the mat-tab-label, but instead of removing it, my label is empty.
So far, this is what I have. My question would be: is it possible to remove the whole tab label without creating a new file and if yes, how can I?
<mat-dialog-content class="ManageTask">
<form [formGroup]="form">
<mat-tab-group mat-stretch-tabs>
<mat-tab>
<ng-template *ngIf="isView()" mat-tab-label>Task details</ng-template>
<div class="left">
<mat-form-field class="full-width">
<input matInput type="text" placeholder="Name" formControlName="name">
<mat-error *ngIf="form.controls['name'].hasError('required')">Name required</mat-error>
</mat-form-field>
<br/>
<mat-form-field class="full-width">
<textarea matInput type="text" placeholder="Description" formControlName="description"></textarea>
<mat-error *ngIf="form.controls['description'].hasError('required')">Description required</mat-error>
</mat-form-field>
</div>
</mat-tab>
<mat-tab *ngIf="isView()" label="Task results">
<div>...MORE CONTENT...</div>
</mat-tab>
</mat-tab-group>
</form>
I'm not sure if I understand the question.certainly you can do it.the correct way to use <ng-template>andngIf like this:
<ng-template [ngIf]="isView()">
<mat-tab label="Task details">...</mat-tab>
</ng-template>
or :
<mat-tab *ngIf="isView()" label="Task details">...</mat-tab>
differences between [ngif] and *ngif:Angular Structural Directives
hopes it help
so I have requirement to have two tabs and a button , i am new to primeng and have created the tabs component, which works fine, see code below, but i am not able to create a button in the same row.
<p-tabView class="info-audit-tabview">
<div class="ui-tabview-panels">
<p-tabPanel header="UnSelected List">
</p-tabPanel>
<p-tabPanel header="Selected List" ng-reflect-header="Audit Trail">
</p-tabPanel>
</div>
</p-tabView>
Using bootstrap classes, add col-md-4 or col-md-6 for tabs. Then place button
<p-tabView class="info-audit-tabview col-md-4">
<div class="ui-tabview-panels">
<p-tabPanel header="UnSelected List">
</p-tabPanel>
<p-tabPanel header="Selected List" ng-reflect-header="Audit Trail">
</p-tabPanel>
</div>
</p-tabView>
<button type="button" pButton label="Export"></button>
As you can see in the documentation on the tabView page, the TabPanel have a specific headerStyleClass that you use like this
<p-tabPanel header="Header 1" headerStyleClass="myCustomClass"></p-tabPanel>
What you can do is give it a class of your own, and style it. Basically, you're creating a tab that looks like a button.
If it's not what you want, please tell me so that I can find another solution for you.