If I have = let a: any = {name: "manolo"}
, is there a way that I can add more fields and values to that variable like a surname?
Thanks.
If I have = let a: any = {name: "manolo"}
, is there a way that I can add more fields and values to that variable like a surname?
Thanks.
let a: any = {name: “manolo”, surname: “doe”} ?
No, I need to do it after let a: any = {name: "manolo"}
, not at the same time.
Object.assign will do what you want, but it’s a very bad idea. Basically, as long as you are using “any”, you are one step away from your code blowing up for a hard-to-debug reason. Type all your variables, as often as you can.
I am not exactly understanding your requirement. Is this what you are looking for?
let a: any = [
{name: “manolo”},
{name: “john”},
…
]
No, the thing is that I need to transform the HttpHeaders from Angular to an Object, because depending of the platform I have to use Angular’s HttpClient or Ionic’s Native HTTP which has to receive an object for the headers parameter.
I’ve finally got it tho with:
private transformHeaders(angularHeaders: any): any {
var nativeHeaders= {};
if(angularHeaders) {
for(let header of angularHeaders.lazyUpdate) {
nativeHeaders[header.name] = header.value;
}
}
return newHeaders;
}
With this I iterate over all headers in a HttpHeaders object and assign them to a new object where they key is the header’s name and the value is the header’s value.
Thanks for the help =)
The more you talk about your adventures with this supposedly-magical plugin that shifts HTTP clients under the hood, the less impressed I get. It causes so much extra work that seems to me completely senseless. Can you explain why it is worth it?
Hi, this isn’t for the plugin I talked about in other posts.
This is for a method that I have created that will use Angular’s HttpClient or Ionic’s Native HTTP depending on if you’re on the browser or on the device. This is because if we use the Native HTTP plugin (which automatically solves CORS), debugging on browser will be a hell since it’s a native plugin.
So the problem that I wanted to solve in this post is because the way of setting headers on Angular’s HttpClient is with HttpHeaders and in Ionic’s Native Plugin it’s with a plain object. So I wanted to find the way on how to construct a HttpHeaders for Angular and then convert it to a plain object as the first post says,
About that library/plugin I’ve talked about in other posts. It’s a great one. Can be found here, sadly, the company I am working for is very big and strict and don’t let us use third party libraries that aren’t something official or supported by Ionic. So I had to create the method I’ve mentioned at the start of this post to use Angular’s HttpClient or Ionic’s Native HTTP.
This library is really really great in my opinion. You just have to install it and use Angular’s HttpClient as you’d normally do and everything will work perfectly, even CORST. Because Angular’s HttpClient has much more features than Ionic’s Native HTTP, for example, the Interceptors that the Native Plugin solves. This plugins does something similar than the method I’ve created but must be much more advanced since I am a begginer.
This plugin has nothing to do with my first post tho.
Seems like a backwards way of going about things to me. CORS is something that should be dealt with server-side. It’s not the mobile app’s job. Also, it makes your tests meaningless, because you’re not really running with the same HTTP client during testing than you will be in production. Sorry, but I’m still not sold.
Yes, but as I said, it’s a very big company of insurances and hospitals. Imagine that they won’t even give us the .mp4 for some videos we have to show and we have instead to take them from the HTML of the sites they are on (it’s on different sites like YT, Vimeo, etc.).
The point is that they wouldn’t just change change the CORS thing so easily since they have much more systems that use the same API we have to use and could affect it (that’s what they say, not what I think). I don’t really get why they do this, since they use Apigee, so I don’t think it’s for security stuff.