how to get parameter from query string in ionic? - ionic-framework

I have some problem on getting parameter from query string. I'm trying using
import { URLSearchParams } from
'#angular/http';
this.params = new URLSearchParams(window.location.search);
this.params1 = this.params.getAll('param');
console.log('parameter: '+JSON.stringify(this.params1))
and when I'm try to access http://localhost:8100/param=1 it getting error Cannot GET /param=1
How can I get that param?

Okay, i'm try using this.platform.getQueryParam('param'); and it working fine.

Related

Getting JSON Data from InAppBrowser IONIC 5

I'm using the cordova in-app-browser plugin. One Page I get back is just a bunch of JSON-Data which i want to store inside my IONIC 5 Project. I could'nt figure out yet how to receive the Data and transfer it to the App yet with the Plugin. Is there such a possibility?
Thank you
To transfer data using InAppBrowser you can pass It by parameters, and also to receive the date you get it from parameters. Follows a small example:
Short way sending data on Page1.ts:
const dataToSend = `/${this.dataOne}/${this.dataTwo}`;
let finalUrl = `https://app-example.io` + dataToSend;
this.inAppB.create(finalUrl, '_system');
Receiving data on Page2.ts:
import { ActivatedRoute } from '#angular/router';
constructor(
private actRoute: ActivatedRoute
){}
ngOnInit() {
this.actRoute.paramMap.subscribe( params => {
console.log('Params => ', params);
if (params) {
let dataReceived = [params['params']['dataOne'], params['params']['dataTwo']];
console.log('dataReceived => ', dataReceived);
}
}
}
Please, adapt it to your code and variables as it is just a short example.

How to get current url using protractor?

I have seen this question, and read this documentation, but still i cannot get the url as string value.
I know that in protractor, you should use the below code to get url:
import {browser} from 'protractor'
browser.waitForAngular();
var url = browser.getCurrentUrl()
console.log("URL is: "+url);
But, when i run the code in the console i have:
URL is: ManagedPromise::253 {[[PromiseStatus]]: "pending"}
Also, the documentation specifies that the result of function is a promise that will be resolved with the current URL.
But, i am wondering, why i am not able to get it as a string?
browser.getCurrentUrl() returns a promise.
You have to resolve the promise to get the current URL.
var currentUrl = browser.getCurrentUrl().then(function(url){
console.log(url);
return url;
});
As you could see from documentation the getCurrentUrl() method return !webdriver.promise.Promise.<string>, translated to people language the method return Promise that contains string. So you need, firstly, to resolve Promise. I highly recommended to read this article for getting understanding.
Example with async ... await:
async function pageUrl() {
const url = await browser.getCurrentUrl();
return url;
}
import {browser} from 'protractor'
browser.getCurrentUrl().then((url) => {
console.log("URL is: "+url);
})

Fetching json from Mongo with Meteor

I am trying to fetch a json object from the mongodb using meteor, but I have no clue why I’m unable to do so.
I need it to be a JSON object only.
One of the entries of the collection looks like this:
[Image taken from Meteor Dev Tools]
Link: https://i.stack.imgur.com/BxRmS.png
I’m trying to fetch the value part by passing the name.
Code on front end:
export default withTracker(() => {
let aSub = Meteor.subscribe(‘allEntries’);
return {
aBoundaries: DataCollection.find({}).fetch()
}
})(Component Name);
The Meteor Call Statement on front-end:
dataFromDb = Meteor.call(‘functionToBeCalled’, ‘Sydney’);
Server-side Code:
Meteor.publish(‘allEntries’, function(){
return DataCollection.find();
});
Meteor.methods({
functionToBeCalled(aName){
return DataCollection.find({name: aName});
}
});
Another of my questions is:
Is there any way that we publish only all the names in the beginning and then publish the values on demand?
Thanks for your help in advance!
I have tried this as well, but it did not work:
functionToBeCalled(aName){
var query = {};
query['name'] = aName;
return DataCollection.find(query).fetch();
}
The issue seems to be with query.
Collection.find() returns data with cursor.
To get an array of objects, use Collection.find().fetch(). The jsons are returned as collection of array like [{json1}, {json2}].
If there is a single document, you can access the json using Collection.find().fetch()[0]. Another alternative is to use findOne. Example - Collection.findOne(). This will return a single JSON object.
use Meteor.subscribe('allEntries'), do not assign it to a variable.
Meteor.subscribe is asynchronous, it's best you ensure that your subscriptions are ready before you fetch data.
Log DataCollection.find({}).fetch() to your console
Check this official reference https://docs.meteor.com/api/pubsub.html#Meteor-subscribe.
Your second question isn't that clear.
Just in case anyone comes here to look for the answer ~~~
So... I was able to make it work with this code on the server:
Meteor.methods({
functionToBeCalled(aName){
console.log(aName);
return DataCollection.findOne({name: aName});
}
});
And this on the client:
Meteor.call('functionToBeCalled', nameToBePassed, (error,response) => {
console.log(error, "error");
console.log(response, "response"); //response here
})
Thanks for the help!

Amazon AWS get object URI

I am using following code to get URI but it gives exception:
s3.putObject(bucket, fileToPut, file.ref.file)
val s3Object = s3.getObject(bucket, fileToPut).orNull
if(s3Object != null){
val assetUrl = s3Object.getObjectContent.getHttpRequest.getURI
}
I am unable to get uploaded object URI
Please help
If you just want the url of the object you could use
s3Client.getResourceUrl("your-bucket", "path/file.txt");

Not able to update data of ParseUser class in Unity3D using Javascript

I am using this code to update data of a Parse User, but the data is not updating nor am I able to retrieve the data.
I am able to do update and retrieve the data for a ParseObject class created by me. Can someone tell me where I am wrong on this?
Out of all the debugs I have set I am able to see only the 1st debug "parse GetSync function passed" and the rest are not printing.
var parseUser: ParseUser;
function FBtoParse(){
var query = ParseUser.Query;
query.GetAsync("Q0D9eBvRee").ContinueWith(GetSync);
Debug.Log("parse GetSync function passed");
Debug.Log("Object ID: "+ parseUser["objectId"]);
Debug.Log("username is : "+ parseUser["username"]);
Debug.Log("User Updated");
}
var GetSync = function (t:System.Threading.Tasks.Task.<ParseUser>){
parseUser = t.Result;
};
function OnGUI{
if (GUILayout.Button("Parse"))
{
FBtoParse();
Debug.Log("Pressed Parse");
}
}
Parse at the moment only allows ParseUsers to update their own object through authentication.
https://parse.com/docs/js/guide#users-security-for-user-objects