Ionic Config Service (how to import)

Viewed 1315

I'm looking at the Ionic Config Service from here: https://ionicframework.com/docs/api/config/Config/

I would like to use the Config functionality to set global configuration variables (in my case API keys). I'm struggling to get it to work however.

Whenever I call:

 config.set('ios', 'green', 'light');

It tells me that config is not defined. However I am unable to import Config as

 import { Config } from 'ionic-angular';

does not work. I thought it could be imported like the Platform Service but it does not seem like it. The documentation lacks further information.

Any help appreciated.

1 Answers

You have to add the Config dependency in the constructor of your component

import {Config } from 'ionic-angular';

constructor(public config:Config){ }

Then, you can access it via

this.config.get('favoriteColor');

Related