I have the following structure:
Structure
In the app.component.ts I have a variable "valor", I want to use that variable in app-routing.module.ts
app.component.ts
app-routing.module.ts
Is that possible?
As Sid T pointed it, you could use Nav Parameters. For instance, you would navigate like this:
app.component.ts
goToThisPage(variable) {
this.navCtrl.push(TargetPage, {
param: variable
});
}
and would retrieve the variable like this:
app-routing.module.ts
this.xyz = this.navParams.get('param');
The best way to use a common variable in any of page is to use provider.
First generate provider in your project using following command :
ionic generate provider provider_name
and declare that common variable as a public in this provider like :
public test:string = "";
Now, import and inject this provider in any of page that you want to use that common variable as below :
import {provider_name} from '../..';
constructor(private testPvdr:TestProvider) {}
Now, you can use that common variable by just provider :
alert(this.testPvdr.test);
You can use Nav Params to transfer data from one page to another.
Related
GET and POST parameters in custom extbase controllers need to be prefixed with the plugin signature to be injected automatically:
<?php
namespace Vendor\Example\Controller;
class SearchController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
public function resultsAction($q = null)
{
//...
}
}
Search term $q is only filled automatically if it is passed as ?tx_example_search[q]=foo.
Is there a way declare that the readable version ?q=foo is also fine, and that this should be injected by extbase as well?
(I know that this breaks when multiple plugins on the same page use that parameter, but that's no problem here.)
(The parameter mapping seems already done when ActionController::processRequest() is called, so it must be done earlier.)
You could use the Extbase Plugin enhancer within the routing configuration.
See here: TYPO3 Advanced routing configuration Docs
TYPO3 would then transform the EXTbase URLs into an readable version.
Example:
without the routeEnhancer: yourdomain.com/?tx_example_search[q]=foo
with the routeEnhancer: yourdomain.com/foo
Tipp: You have to define all GET Params otherwise TYPO3 will show the cHash Param.
You can use the method \TYPO3\CMS\Core\Utility\GeneralUtility::_GP($var) in order to retrieve parameters from global variables GET/POST.
Or also \TYPO3\CMS\Core\Utility\GeneralUtility::_GET($var) or \TYPO3\CMS\Core\Utility\GeneralUtility::_POST($var).
Take care of security, those parameters are not sanitized !
If you really want to add the parameter to the action, you have to create an initializeAction() and set the parameter, something like this I guess :
public function initializeResultsAction() {
$myVar = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('q');
$this->request->setArgument('q', $myVar);
}
On main.dart I get response from api username and set `String myUsername = 'stackoverflow';
How on all page use myUsername as global variable?
the answer above is right ,
however if you don't want to make a singleton class,
all you can do is, save it to shared preference, using the
shared_preferences
myPreference.setString("userName", Your user name)
and get it using
myPreference.getString("userName")
You can create a Singleton like this:
class SingletonTest{
String myUsername;
SingletonTest._private();
static SingletonTest _instance = SingletonTest._private();
static SingletonTest get instance => _instance;
}
After that, you can access it from anywhere in your code using:
var singl = SingletonTest.instance;
For more examples refer to:
How to build a Singleton in dart
Or you can use Provider Pattern, more info about it here:
Provider Pattern
I want to set use Strings from an API as Fontawesome icons. I have added the font_awesome_flutter plugin.
I need to store the icon name in a variable and then create an object from it. I would imagine it to like this:
String iconfromApi = 'suitcase';
Icon(FontAwesomeIcons.iconfromApi);
As described here, you would need have access to the dart:mirrors pacakage, which is not avaible in Flutter.
A solution that would work in Flutter is creating a helper method. This means that you will have to code in cases for all icon names you want to use. If you do not want to write all of that by hand, you can take a look at a package like reflectable as mentioned in the GitHub comment or potentially source_gen or build_runner, however, I am not sure if the latter two are well suited.
Anyways, what you could also write by hand is a helper function like this:
IconData fontAwesomeIconFromString(String name) {
switch (name) {
case 'suitecase':
return FontAwesomeIcons.suitecase;
case 'gamepad':
return FontAwesomeIcons.gamepad;
// ...
}
}
In your code, you can now use it like this:
String iconfromApi = 'suitcase';
Icon(fontAwesomeIconFromString(iconFromApi));
I am trying to use this library "react-jsonschema-form" to create forms using react and jsonschema.
I am trying to use it in my project as described in the example from the website by including the .js file via cdn. It is not working. The exported component "Form" is undefined.
I had a look at this similar question Using React component from js source maps but I could not understand the solution offered. I am supposed to alias the default export of JSONSchemaForm. But what is JSONSchemaForm? and where can I find it? Is it another library to be included?
Here is what I tried to do:
Using Require.js I have imported the cdn library:
var require = {
baseUrl: "/js/",
waitSeconds: 600,
paths: {
'react-forms': ['https://unpkg.com/react-jsonschema-form/dist/react-jsonschema-form']
},
}
Then in my code I import the library:
var rf = require('react-forms')
But now when I access Form (rf.Form), it is undefined. I had a look at the "react-jsonschema-form.js" source code. "Form" is defined no where.
From the instructions of the library page it is said:
You'll also need to alias the default export property to use the Form component:
const Form = JSONSchemaForm.default;
// or
const {default: Form} = JSONSchemaForm;
But JSONSchemaForm is also undefined.
So I don't know what I am doing wrong. How can I use "react-jsonschema-form" library by including it as a script tag?
Thank you community.
1. Include the cdn path
<script src="https://cdn.jsdelivr.net/npm/react-jsonschema-form#1.0.3/dist/react-jsonschema-form.js"></script>
2.By using field get the access of jsonformDefaultValues;
` <script type="text/babel"
const fields = JSONSchemaForm.default
return(
<Form
schema={schema}
uiSchema={uiSchema}
field={fields}
onSubmit={onSubmit}
</Form>)
</script>`
I was able to solve this problem and I am reporting here the solution for any one facing a simlilar issue. To use react-jsonschema-form via cdn script tag (with require.js):
include this library via require.js by indicating the url path :
paths: {
'react-forms': ['https://unpkg.com/react-jsonschema-form/dist/react-jsonschema-form']
}
include this polyfill library: cdn.polyfill.io/v2/polyfill.min.js
Make sure to use the latest react version ( version v15)
In you code, require the library and alias its default export like this:
var rf = require("react-forms");
const Form = rf.default;
(This is because I am using require.js module system. For another module system, you may use JSONSchemaForm.default)
I'm using laravel 4.0 for my web service project. I try to assign relative path to controller subfolder but still got the error message.
This is my router looks like
Route::group(array('prefix' => 'merchant'), function()
{
Route::resource('index', 'ProductController#showIndex');
Route::resource('product', 'CategoryController#showIndex');
Route::resource('general', 'GeneralController#showIndex');
});
Current path
/app/controllers/ProductController.php
I want to be like this one
/app/controllers/merchant/ProductController.php
Thanks a lot in advance.
You need a namespace to achieve that.
In your controller folder make a directory called merchant and place your ProductController.php inside Merchant directory.
Then open your ProductController.php and use the following namespace on top of the file.
<?php namespace Merchant;
class ProductController extends /BaseController
{
After that edit your route file:
Route::get('index', 'Merchant\ProductController#showIndex');
Remove the Route::group(array('prefix' => 'merchant'), function(). Prefix used when you have a common url for more than one routes.
For example:
http:://laravel.com/xyz/products
http:://laravel.com/xyz/category
http:://laravel.com/xyz/posts
Here xyz is common in every URL. So, In this case, you can use group routing with prefix xyz
One more thing, I can see, you have used resource controller.
Route::resource('index', 'ProductController#showIndex');
Route::resource('product', 'CategoryController#showIndex');
Route::resource('general', 'GeneralController#showIndex');
Do you know that By default, for resource controller, Laravel will generate 7 routes. So, You don't need to create #showIndex function when using resource controller.
Route::resource('index', 'ProductController');
Route::resource('product', 'CategoryController');
Route::resource('general', 'GeneralController');
More about resource controller:
http://laravel.com/docs/controllers#resource-controllers