Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic Config Service (how to import)

Tags:

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.

like image 687
jonas-l-b Avatar asked Nov 14 '17 18:11

jonas-l-b


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');

like image 161
Antikhippe Avatar answered Sep 22 '22 13:09

Antikhippe