angular - How to set global options for components with angular2? -


i'm using component mydatepicker in angular2 https://github.com/kekeh/mydatepicker. best practice set global option this? example, if want option dateformat = 'dd/mm/yyyy' create own component option , put datepicker in template using <my-component> instead of <my-datepicker>. i'm sure it's bad way that.

more in general should insert component in 'myview.html' template using when mydatepickeroptions set 'myview.ts'. i'would edit global options instance of my-date-picker , preserve chance of editing options individual instances.

there 2 ways handle scenario.

1) if don't want change value of configuration.

in case have define 1 common configuration object.

export const commonconfig = {     datepickerconfig: {     dateformat : 'dd-mm-yyyy',     displaytime: true,     ....     },     // here can put other configuration } 

this exported constant accessible via import statement in component, service.

import { commonconfig } './<path common config define>'; 

2) if want change value of configuration application.

in case have create 1 global level service , inject in app.module.ts file's provider section. when defining global service provider section of app.module.ts there 1 instance available entire application. so, can access data/configuration service or can set/modify existing configuration.

i hope helpful you.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -