angular

add new property in Typescript object

爷,独闯天下 提交于 2021-02-19 02:42:40
问题 I'm trying to add new property in object, but typescript given error. error TS2339: Property 'qty' does not exist on type 'Object'. product: Object = {qty: Number}; foo(){ this.product.qty = 1; } 回答1: Object is the wrong annotation. Change your annotation: product: {qty: number} = {qty: 0}; foo(){ this.product.qty = 1; } 回答2: Number is a data type not a value. the object only accept the value not datatype. So you can't declare number as a value try this simple way product: any; foo(){ this

add new property in Typescript object

送分小仙女□ 提交于 2021-02-19 02:41:05
问题 I'm trying to add new property in object, but typescript given error. error TS2339: Property 'qty' does not exist on type 'Object'. product: Object = {qty: Number}; foo(){ this.product.qty = 1; } 回答1: Object is the wrong annotation. Change your annotation: product: {qty: number} = {qty: 0}; foo(){ this.product.qty = 1; } 回答2: Number is a data type not a value. the object only accept the value not datatype. So you can't declare number as a value try this simple way product: any; foo(){ this

Angular form validation: compare two fields in different form groups

人盡茶涼 提交于 2021-02-19 02:24:24
问题 I'm sorry if it's a duplicate of someone question. I didn't find a solution for my problem. Can anybody explain or give an example how to compare two fields in one form but in different form groups? Here is code snippet to see how my form and validator are look like: private createForm() { const testGroups = { groupOne: this.fb.group({ fieldOne: this.fb.control(null) }), groupsTwo: this.fb.group({ fieldTwo: this.fb.control(null, [this.matchValidator]) }) }; this.testForm = this.fb.group

Is it possible to get minlength value from formcontrol?

女生的网名这么多〃 提交于 2021-02-19 01:34:04
问题 So i have my form validation. And my question is can i get for example a minlength value which i passed at creating formControl? I havent found any information. This is my dumb component and i want to get minlength value to pass to information. Now i need to pass it via @Input(). title: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(20)]] . <div class="validation-window"> <p *ngIf="errors.required"> {{field}} required </p> <p *ngIf="formControl.hasError('minlength')"

Is it possible to get minlength value from formcontrol?

走远了吗. 提交于 2021-02-19 01:33:29
问题 So i have my form validation. And my question is can i get for example a minlength value which i passed at creating formControl? I havent found any information. This is my dumb component and i want to get minlength value to pass to information. Now i need to pass it via @Input(). title: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(20)]] . <div class="validation-window"> <p *ngIf="errors.required"> {{field}} required </p> <p *ngIf="formControl.hasError('minlength')"

Angular ngModel doesn't update when `ngModelChange` keeps value

谁说胖子不能爱 提交于 2021-02-18 22:58:05
问题 I have a text field represented as: field = {text: "", valid: false} , and an input with [(ngModel)]="field.text" . I want to make that field only accept a defined set of characters (for this issue, numbers), and doing (keypress) doesn't work on mobile, so I did: (ngModelChange)="fieldChanged(field)" The method does the following: fieldChanged(field) { console.log(field.text); field.text = Array.from(field.text).filter((char:string) => "0123456789".indexOf(char) != -1).join(""); console.log

resolver on lazy loading angular

喜夏-厌秋 提交于 2021-02-18 22:49:17
问题 is there a way to add a resolver before loading a lazy load module? i tried to add resolve to the routs configuration but it is not triggered, also didn't find any thing useful about it on the web. any help would be appreciated import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; // services import {SecondResolverService} from "./second.resolver.service"; const routes: Routes = [ { path: 'first' , loadChildren: './first/first.module#FirstModule' },

Angular w/ Angular Material - Dialog theme broken

跟風遠走 提交于 2021-02-18 22:17:09
问题 Hello i'm having an issue with Angular Material theme breaking in a Dialog Component, where the color of text and other components aren't working in the ways they should. In app.component I have a setting icon button to open a dialog main.settings.dialog but when it opens as seen in the picture below the coloring is not fitting the Dark Theme. Any insight as to why this isn't working in a normal way would be greatly appreciated as i can't find a way to fix this. Live example site Link to full

Angular 2+ Google Maps get coordinates from click position on map to update marker position

谁说我不能喝 提交于 2021-02-18 22:12:33
问题 I want to do something which is probably really simple however I can't seem to figure it out. I integrated the Angular2+ Google Maps module to my Angular project (https://angular-maps.com/). Now I want to be able to replace the marker by clicking somewhere on the map. In order to do this I need to fetch the coordinates of the location where the user clicked on the map. If I have these coordinates I can update the longitude and latitude to move the marker. However I am not sure how to fetch

Angular 2+ Google Maps get coordinates from click position on map to update marker position

房东的猫 提交于 2021-02-18 22:12:20
问题 I want to do something which is probably really simple however I can't seem to figure it out. I integrated the Angular2+ Google Maps module to my Angular project (https://angular-maps.com/). Now I want to be able to replace the marker by clicking somewhere on the map. In order to do this I need to fetch the coordinates of the location where the user clicked on the map. If I have these coordinates I can update the longitude and latitude to move the marker. However I am not sure how to fetch