Skip to content

Instantly share code, notes, and snippets.

@neojp
Created November 21, 2020 20:43
Show Gist options
  • Save neojp/02ac6f708d1861816df0f1bce504729a to your computer and use it in GitHub Desktop.
Save neojp/02ac6f708d1861816df0f1bce504729a to your computer and use it in GitHub Desktop.
stackoverflow-64896144
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class FirstController extends Controller {
@service settings;
@action changeLanguajeToEN () {
this.settings.lang = 'EN';
}
@action changeLanguajeToCN () {
this.settings.lang = 'CN';
}
}
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('first', { path: '/' });
});
export default Router;
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
export default class SettingsService extends Service {
@tracked lang = 'EN'
}
<div class="wrapper">
<h3>First route</h3>
<hr class="gold">
<p>
<button type="button" {{on "click" this.changeLanguajeToEN}}>Change to English</button>
<button type="button" {{on "click" this.changeLanguajeToCN}}>Change to Chinese</button>
</p>
<p>The current language is: <code>{{this.settings.lang}}</code></p>
</div>
{{outlet}}
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false,
"_APPLICATION_TEMPLATE_WRAPPER": true,
"_JQUERY_INTEGRATION": true
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js",
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment