angular5

What is the function of --poll flag in CLI

无人久伴 提交于 2019-12-20 06:28:43
问题 I was searching a solution for an issue which is in my angular project, ng serve --watch was not detecting changes in some of the files. And I got a solution which says use --poll=2000 It really worked. But there are no clear information available about the function of flag poll . 回答1: In cases where Angular CLI is running in a shared directory on linux VM on a windows host the webpack dev server isn't detecting file changes from the host environment. (ex: Whenever a docker dev environment is

angular 5 populate form fields using other field values if checkbox is selected

我怕爱的太早我们不能终老 提交于 2019-12-20 04:38:38
问题 I've got two sections of forms - correspondence address and residential address. The goal is to copy/pass values from one field to another if a checkbox is checked. Kindly see below use case populate the correspondence address fields with the values of the residential address form fields iff a checkbox (same as residential address) is checked Should any form field in the residential address change after checking the checkbox, pass the change(s) realtime to the field in the correspondence

“Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response”

余生颓废 提交于 2019-12-20 03:42:55
问题 service.ts : import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; const httpOptions = { // headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost:8080', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Headers':'X-Requested-With' }), headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http

Angular 5 - How to call a function when HTML element is created with *ngFor

情到浓时终转凉″ 提交于 2019-12-20 03:21:07
问题 Currently I'm working in a view where I have to dynamically create HTML elements. I'm creating the HTML elements with *ngFor directive bounded with an Array. I need to refer the new HTML element with JQuery selector after push a new object into the Array, but the HTML element is not rendered yet. How can I trigger a function just after the HTML element is ready ? Thanks in advance. 回答1: You can follow below steps inside the component:- 1) On ngOnInit(), you can write logic which is

How to bind custom error to a Template Driven form input field in angular5

断了今生、忘了曾经 提交于 2019-12-20 01:03:48
问题 In case of Model Driven form or Reactive form we can bind the custom error to an input field as follows: In Component: sampleForm.controls["formControlName"].setErrors({ 'incorrect': true }) ; My question is how can we do the same thing in case of Template Driven form? 回答1: You can make use of View Child in this scenario get an instance of the ngForm in the component backend model and then add all the validations and errors to it Something like this f: NgForm; // f is nothing but the template

angular service-worker - handling push notification click

杀马特。学长 韩版系。学妹 提交于 2019-12-19 19:40:37
问题 How do I handle the push notification click in angular service worker. The SWPush does not have any methods. I have tried referencing a js which listens to the "notificationclick" event handler but it never got fired on the click of the notification button. 回答1: Call SWPush#requestSubscription. Here's a good article 回答2: I had to update my package.json to: "@angular/service-worker": "7.1.0" then this worked for me: this.swPush.notificationClicks.subscribe((result) => { console.log('clicked',

Angular 5 file upload: Failed to set the 'value' property on 'HTMLInputElement'

放肆的年华 提交于 2019-12-19 16:54:51
问题 I have a form for uploading a file in an angular 5 app, and as I have copied it exactly from a code I had written a while ago, I can swear it had worked before. Here is my HTML code: <form [formGroup]="form" (ngSubmit)="onSubmit()"> <div class="form-group"> <label>File:</label> <input #theFile type="file" (change)="onFileChange($event)" accept=".png" class="form-control" formControlName="content" /> <input type="hidden" name="fileHidden" formControlName="imageInput"/> <!-- [(ngModel)]="model

Angular 5 file upload: Failed to set the 'value' property on 'HTMLInputElement'

我是研究僧i 提交于 2019-12-19 16:54:26
问题 I have a form for uploading a file in an angular 5 app, and as I have copied it exactly from a code I had written a while ago, I can swear it had worked before. Here is my HTML code: <form [formGroup]="form" (ngSubmit)="onSubmit()"> <div class="form-group"> <label>File:</label> <input #theFile type="file" (change)="onFileChange($event)" accept=".png" class="form-control" formControlName="content" /> <input type="hidden" name="fileHidden" formControlName="imageInput"/> <!-- [(ngModel)]="model

Angular 5 FormArray get data from database and show rows

拈花ヽ惹草 提交于 2019-12-19 11:24:09
问题 I am just a newbie to angular. I have create a event component where user enters the event name with packages. When user creates an event it has the functionality for creating multiple packages with add and remove row. For that I have used FormArray . Everything is fine here. But when I am trying to get those values in event edit component I am getting the value of event name but when I am trying to get the packages details I am little bit confused in showing rows with filled values. Here is

How to Know Which component is loaded in router-outlet in Angular 5 and above

倖福魔咒の 提交于 2019-12-19 09:39:23
问题 This my ap.component.html <app-header></app-header> <router-outlet></router-outlet> <app-footer></app-footer> How to know which component is loaded in Router outlet and then add a class on header or body depending on the component. Just Like if Home is loaded then add a home class on the body. or if 404 page then notfound class on body My Routing const routes: Routes = [ { path: '' , component: HomeComponent}, { path: 'directory' , component: DirectoryComponent }, { path: 'directory/:slug' ,