angular6

Why is constructor call each time after injection of service?

≡放荡痞女 提交于 2021-02-08 09:52:46
问题 I use Angular 2. I use singleton service @NgModule({}) in section providers: ['MenuService'] I use MenuService . MenuService looks as: @Injectable() export class MenuService { constructor(private userService: UserService, private i18nService: I18nService) { console.log('Called'); } } There are two components where I inject this service: export class HeaderComponent { constructor(private menuService: MenuService) {} } export class HomeComponent { constructor(private menuService: MenuService) {

Multiple key binding on (keydown) event in angular 6

这一生的挚爱 提交于 2021-02-08 06:12:30
问题 I have used (keydown) event in angular 6 to bind key inputs So on enter of 'Tab' and 'Enter' key i have to do my functionality and added a event.prevent default But when Shift + Tab is entered it is also preventing the event .html <input type="text" [(ngModel)]="Result1 (keydown)="onKeydownMain($event)" > I dont want (keydown.shift.tab) event seperate.. .ts public onKeydownMain(event): void { if (event.key === "Enter" || event.key === "Tab") { event.preventDefault(); // My Functionality goes

Multiple key binding on (keydown) event in angular 6

心已入冬 提交于 2021-02-08 06:10:30
问题 I have used (keydown) event in angular 6 to bind key inputs So on enter of 'Tab' and 'Enter' key i have to do my functionality and added a event.prevent default But when Shift + Tab is entered it is also preventing the event .html <input type="text" [(ngModel)]="Result1 (keydown)="onKeydownMain($event)" > I dont want (keydown.shift.tab) event seperate.. .ts public onKeydownMain(event): void { if (event.key === "Enter" || event.key === "Tab") { event.preventDefault(); // My Functionality goes

Multiple key binding on (keydown) event in angular 6

旧巷老猫 提交于 2021-02-08 06:09:36
问题 I have used (keydown) event in angular 6 to bind key inputs So on enter of 'Tab' and 'Enter' key i have to do my functionality and added a event.prevent default But when Shift + Tab is entered it is also preventing the event .html <input type="text" [(ngModel)]="Result1 (keydown)="onKeydownMain($event)" > I dont want (keydown.shift.tab) event seperate.. .ts public onKeydownMain(event): void { if (event.key === "Enter" || event.key === "Tab") { event.preventDefault(); // My Functionality goes

How to create Cascading Drop Down (Country and State list) In Angular 6

不羁的心 提交于 2021-02-07 18:46:27
问题 How to create Cascading Drop Down (Country and State list) In Angular 6. I want a fully country and there state list in angular 6. anyone who know that pl z share your idea. 回答1: DEMO ----> Cascading Drop Down (Country and State list) HTML: <label>Country</label> <div title="Please select the country that the customer will primarily be served from"> <select placeholder="Phantasyland" (change)="changeCountry($event.target.value)"> <option *ngFor ="let count of countryList">{{count.name}} <

Upgrading ngx-bootstrap 3.0.1 to 4.0.1

怎甘沉沦 提交于 2021-02-07 18:11:35
问题 While Upgrading from ngx bootstrap 3.0.1 to 4.0.1 am getting the following error.Replaced the node_modules, package.json still getting the same errors. Angular Version : Angular 6, Typescript: 2.7.2. Errors: ERROR in node_modules/ngx-bootstrap/chronos/utils/type-checks.d.ts(8,62): error TS2304: Cannot find name 'Extract'. node_modules/ngx-bootstrap/datepicker/reducer/bs-datepicker.actions.d.ts(5,33): error TS1039: Initializers are not allowed in ambient contexts. node_modules/ngx-bootstrap

Upgrading ngx-bootstrap 3.0.1 to 4.0.1

倾然丶 夕夏残阳落幕 提交于 2021-02-07 18:07:34
问题 While Upgrading from ngx bootstrap 3.0.1 to 4.0.1 am getting the following error.Replaced the node_modules, package.json still getting the same errors. Angular Version : Angular 6, Typescript: 2.7.2. Errors: ERROR in node_modules/ngx-bootstrap/chronos/utils/type-checks.d.ts(8,62): error TS2304: Cannot find name 'Extract'. node_modules/ngx-bootstrap/datepicker/reducer/bs-datepicker.actions.d.ts(5,33): error TS1039: Initializers are not allowed in ambient contexts. node_modules/ngx-bootstrap

Create Component Dynamically with parameters

别来无恙 提交于 2021-02-07 14:41:13
问题 I have a component which is dynamically created with ComponentFactoryResolver this.container.clear(); let factory = this.resolver.resolveComponentFactory(DynamicComponent); this.componentRef = this.container.createComponent(factory); template: '...<child-component [param1]="param1"></child-component>...'; The problem is DynamicComponent's template has child component and input bindings. Is there a way to pass parameters to child component when creating the component dynamically? 回答1: Yes like

Create Component Dynamically with parameters

给你一囗甜甜゛ 提交于 2021-02-07 14:40:55
问题 I have a component which is dynamically created with ComponentFactoryResolver this.container.clear(); let factory = this.resolver.resolveComponentFactory(DynamicComponent); this.componentRef = this.container.createComponent(factory); template: '...<child-component [param1]="param1"></child-component>...'; The problem is DynamicComponent's template has child component and input bindings. Is there a way to pass parameters to child component when creating the component dynamically? 回答1: Yes like

Angular 6 Server Side Rendering (SSR) set status code from Component

百般思念 提交于 2021-02-07 10:37:20
问题 Is there any way to set status code like 404, 401, 500 as per requirement? I am using Angular 6. There are lots of tutorials showing solutions but those are old and not working at all. All provides showing solutions regarding different server.ts file which is not related to new file showing on Angular site. I am able to render all pages server side. When it has some unexpected content in URL, I am change route to 404 page with skipping location change option. While calling 404 component, I