angular

How to set a default month in an input element?

我怕爱的太早我们不能终老 提交于 2021-02-20 19:49:51
问题 Say I have an input element like this: <input type="month"> How can I set the default value of this input element to the current month? 回答1: You may use some javascript: const monthControl = document.querySelector('input[type="month"]'); const date= new Date() const month=("0" + (date.getMonth() + 1)).slice(-2) const year=date.getFullYear() monthControl.value = `${year}-${month}`; <input type="month"> 回答2: You have to construct new Date and query your input, then do something like: let date =

How to cast observable response to local object

浪子不回头ぞ 提交于 2021-02-20 19:23:52
问题 In current Angular 6 application there is a subscribe to observable (response from RESTful service) this.activatedRoute.data.subscribe(({bag}) => { console.log(bag); this.bag= bag; }); the subscription is waiting response from resolver @Injectable({ providedIn: 'root' }) export class BagResolver implements Resolve<Bag> { constructor(private service: BagService) {} resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { const id = route.params['id'] ? route.params['id'] : null; if

Need to access service in function

坚强是说给别人听的谎言 提交于 2021-02-20 18:43:35
问题 I have a service (AuthService) that I need to access in my restangularInit function (in my app.module.ts) but I don't know how, I can't get access to it. I have tried to move it to the class AppModule but by then it´s to late. Calling the service functions eg. getToken works as expected. import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import {

Why ng-template is not working in Angular?

流过昼夜 提交于 2021-02-20 18:03:14
问题 We can't use *ngFor and *ngIf on the same element. A technique is to nest them. Almost everywhere it's OK, except in tables when we want to both loop over tr and print them conditionally. As suggested here we should use <template> , or <ng-template> elements, so that it won't be printed to the DOM. But I can't make it work. It simply doesn't print out anything. Here's a plunker to show it in action. What should I do? 回答1: As *ngIf is rendered as [ngIf], try using [ngIf] directly on template

Why ng-template is not working in Angular?

非 Y 不嫁゛ 提交于 2021-02-20 18:02:55
问题 We can't use *ngFor and *ngIf on the same element. A technique is to nest them. Almost everywhere it's OK, except in tables when we want to both loop over tr and print them conditionally. As suggested here we should use <template> , or <ng-template> elements, so that it won't be printed to the DOM. But I can't make it work. It simply doesn't print out anything. Here's a plunker to show it in action. What should I do? 回答1: As *ngIf is rendered as [ngIf], try using [ngIf] directly on template

Why ng-template is not working in Angular?

坚强是说给别人听的谎言 提交于 2021-02-20 18:02:24
问题 We can't use *ngFor and *ngIf on the same element. A technique is to nest them. Almost everywhere it's OK, except in tables when we want to both loop over tr and print them conditionally. As suggested here we should use <template> , or <ng-template> elements, so that it won't be printed to the DOM. But I can't make it work. It simply doesn't print out anything. Here's a plunker to show it in action. What should I do? 回答1: As *ngIf is rendered as [ngIf], try using [ngIf] directly on template

How to apply some style to the table row in angular material table

喜你入骨 提交于 2021-02-20 16:32:26
问题 I have this table : <div class="table-container"> <table mat-table [dataSource]="dataSource"> <mat-divider></mat-divider> <!-- title column --> <ng-container matColumnDef="title"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th> <td mat-cell *matCellDef="let element"> {{element.title}} </td> </ng-container> <!-- code column --> <ng-container matColumnDef="description"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }}

How to apply some style to the table row in angular material table

天涯浪子 提交于 2021-02-20 16:31:59
问题 I have this table : <div class="table-container"> <table mat-table [dataSource]="dataSource"> <mat-divider></mat-divider> <!-- title column --> <ng-container matColumnDef="title"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th> <td mat-cell *matCellDef="let element"> {{element.title}} </td> </ng-container> <!-- code column --> <ng-container matColumnDef="description"> <th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }}

How to access properties of angular material components?

三世轮回 提交于 2021-02-20 10:13:01
问题 I'm fairly new to angular in general, i have built my first few apps with it and right now I'm working on some project that contains angular material. When i go to this site i see lots of properties of the MatSelect directive. There is one property called 'empty: boolean' that I would like to access in some way, but i don't know how, can you help me? 回答1: Pay attention to Exported as:matSelect . You can reference it by template reference variable(#var) or by ViewChild: <mat-select #matSelect

How to access properties of angular material components?

回眸只為那壹抹淺笑 提交于 2021-02-20 10:12:23
问题 I'm fairly new to angular in general, i have built my first few apps with it and right now I'm working on some project that contains angular material. When i go to this site i see lots of properties of the MatSelect directive. There is one property called 'empty: boolean' that I would like to access in some way, but i don't know how, can you help me? 回答1: Pay attention to Exported as:matSelect . You can reference it by template reference variable(#var) or by ViewChild: <mat-select #matSelect