I have Login Page.
Structure as below:
FirstName:
LastName:
Address:
Street:
Contact number:
Email:
I have create Address using FormArray. I'm trying to write uni test case to check field empty in Address array.
I tried accessing the value as
let street = component.form.controls['address].get('Street'); expect(street.valid).toBeFalsy();
Showing error as
cannot read property valid of undefined
Related
Im trying to extract IP info from IPinfo website but be able to have the query have the IP set prior to the extract data function so its easy to change the searched IP and possibly use it for searching the IP when using Signinlogs etc... see below roughly what iv got atm.
let _IP = "'[INSERT IP HERE]'"; //IP im searching for
let _link = strcat('#"https://ipinfo.io/', _IP, '/json"'); //attempt to concat the IP into the URL
let IPCheck = externaldata(ip: string, city: string, region : string, country : string, org : string )[_link] //external data function to pull json data from URL
with(format=multijson);
IPCheck
The below works. as I want it to
let IPCheck = externaldata(ip: string, city: string, region : string, country : string, org : string )[#"https://ipinfo.io/[INSERT IP HERE]/json"] //external data function to pull json data from URL
with(format=multijson);
IPCheck
But want to create the URL before hand, creating this as a string does NOT appear to work
Any ideas on how to work around this or a better way of extracting this data?
This can be done using the http_request plugin.
Having said that, I have no idea why you would like to do such a thing within ADX.
let IP = "8.8.8.8";
let URL = strcat("https://ipinfo.io/", IP, "/json");
evaluate http_request(URL)
ResponseHeaders
ResponseBody
ResponseStatusCode
ResponseReasonPhrase
{"access-control-allow-origin":"*","x-frame-options":"SAMEORIGIN","x-xss-protection":"1; mode=block","x-content-type-options":"nosniff","referrer-policy":"strict-origin-when-cross-origin","x-envoy-upstream-service-time":"1","strict-transport-security":"max-age=2592000; includeSubDomains","vary":"Accept-Encoding","Alt-Svc":"h3=":443"; ma=2592000,h3-29=":443"; ma=2592000","Transfer-Encoding":"chunked","Date":"Fri, 30 Dec 2022 11:16:14 GMT","Via":"1.1 google"}
{"ip":"8.8.8.8","hostname":"dns.google","anycast":true,"city":"Mountain View","region":"California","country":"US","loc":"37.4056,-122.0775","org":"AS15169 Google LLC","postal":"94043","timezone":"America/Los_Angeles","readme":"https://ipinfo.io/missingauth"}
200
OK
I'm new to Angular and am struggling to build my first app. I have a web service which returns some json in this format:
<PolicyHolderClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Title>Mr</Title>
<Forename>J</Forename>
<Surname>Smith</Surname>
<Address1>21 Somewhere Street</Address1>
<Address2>Hereton</Address2>
<Address3>Theresville</Address3>
<Address4/>
<Address5/>
<Postcode>TH8 6AB</Postcode>
<Telephone>01234567890</Telephone>
<Email>name#provider.co.uk</Email>
</PolicyHolderClass>
I want to have some code which will get the data from the web service into a format I can use. I have created an interface
interface PHDETAILS {
Title: string,
Forename: string,
Surname: string,
Address1: string,
Address2: string,
Address3: string,
Address4: string,
Address5: string,
Postcode: string,
Telephone: string,
Email: string
}
and I have this code to retrieve the data
const phDetails: PHDETAILS = this.http.get('HelloWorld?PolicyNumber=' + policyNumber.toString());
Unfortunately this isn't working, and i'm getting this in the console
error TS2740: Type 'Observacle<Object>' is missing the following properties from type 'PHDETAILS': Title, Forename, Surname, Address1, and 7 more.
So, can anyone tell me how I get the json data into phDetails? I am using Angular 13. I would prefer a simple approach as i'm a newbie, but it can be quick and dirty as long as it gets the job done. Thanks.
Background: Project uses Yelp API in JSON to sift through business data. Two types of endpoints are use - https://www.yelp.com/developers/documentation/v3/business_search and https://www.yelp.com/developers/documentation/v3/business. The first part of this projects works as expected where the business_search api is parsed, saved as a list of strings and converted to a Business objects when it is needed to be displayed. The JSON -> Object code is as follows:
factory Business.fromJSON(Map<String, dynamic> json) {
return Business(
rating: json['rating'],
price: json['price'],
phone: json['phone'],
id: json['id'],
name: json['name'],
alias: json['alias'],
isClosed: json['is_closed'],
reviewCount: json['review_count'],
url: json['url'],
imageUrl: json['image_url'],
);
}
The code works when a call is converted from the business/search endpoint, with the JSON printout being:
json = {rating: 4.5, price: $$, phone: +16316751500, id: D5dS2-8JXhZxo3BzMLV3xQ, name: Ichi sushi & ramen, alias: ichi-sushi-and-ramen, is_closed: false, review_count: 128, url: https://www.yelp.com/biz/ichi-sushi-and-ramen?adjust_creative=Aj73ii92JG9IDLNvRyn_Ow&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=Aj73ii92JG9IDLNvRyn_Ow, image_url: https://s3-media1.fl.yelpcdn.com/bphoto/Phib_AwTkdD_kBV8r7179Q/o.jpg}
The Issue: I encounter the following exception
[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: FormatException: Unexpected character (at character 2)
{id: D5dS2-8JXhZxo3BzMLV3xQ, alias: ichi-sushi-and-ramen...
^
when this response from business/details is called, saved and attempted to be converted to objects:
json = {id: D5dS2-8JXhZxo3BzMLV3xQ, alias: ichi-sushi-and-ramen, name: Ichi sushi & ramen, image_url: https://s3-media1.fl.yelpcdn.com/bphoto/Phib_AwTkdD_kBV8r7179Q/o.jpg, is_claimed: true, is_closed: false, url: https://www.yelp.com/biz/ichi-sushi-and-ramen?adjust_creative=Aj73ii92JG9IDLNvRyn_Ow&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_lookup&utm_source=Aj73ii92JG9IDLNvRyn_Ow, phone: +15836751500, display_phone: (583) 675-1500, review_count: 128, categories: [{alias: sushi, title: Sushi Bars}, {alias: ramen, title: Ramen}], rating: 4.5, location: {address1: 200 Country Rd, address2: null, address3: , city: Bayshore, zip_code: 11803, country: US, state: NY, display_address: [200 Country Rd, Bayshore, NY 11803], cross_streets: }, coordinates: {latitude: 40.92842, longitude: -73.116}, photos: [https://s3-media1.fl.yelpcdn.com/bphoto/Phib_AwTkdD_kBV8r7179Q/o.jpg, https://s3-media2.fl.yelpcdn.com/bp<…> (*My note: debugger truncates with <...>*)
What is going wrong here? I have been trying many (and I mean many) different cases to rule out what the issue is but cannot find anything that is blatantly amiss. The only difference I can see is that the first type of call (business/search) starts with "rating" and contains fewer fields while the second type of call (business/details) returns much more data (note that I do not need much of it and hence do not need it in the Business object, but the nature of Yelp's api requires I do it in this way) and starts with the "id" field instead. Are these differences to blame and what does this error mean? Can you "plug in" a JSON to an object that has more fields than needed properties as I would like to keep the Business object as versatile as possible? Regardless, how could this be resolved? If more info is needed, please let me know. Thank you for your help and time!
After further analyzing the code, #KhashayarMotarjemi's suggestion tipped me off on a possible problem: the way the data was encoded. To save the data, I ran the the JSON through the toString() method, stripping the data of all of its " " and making it unable to be correctly parsed as JSON later on when retrieved from memory. The correct method would be jsonEncode(yourData) as this converts it to a string to be saved, but preserves the format needed when decoded down the line. So to anyone reading, if you are trying to store your JSON as a string, you must use jsonEncode() and not toString() when doing so. I hope this can help someone in the future!
If I log the full data from an Angular client I get
object { type: "message", target: {_}, errorCode: undefiend,
errorMessage: undefined, data: "{\"data\":[\"124",\"611\"]}",
lastEventId: ""}
I want to grab the {\"data\":[\"124",\"611\"]} part to send it as json to a client. Using JSON.parse(data.data) though gives me
data: "{\"data\":[\"124",\"611\"]}", lastEventId: ""}
Is it possible to just grab the "{\"data\":[\"124",\"611\"]}" since otherwise the client has problems with the deserialization.
Let's say you have your initial string in myobject_string.
Then, you extract the JSON to a Javascript object with: const myobject = JSON.parse(myobject_string).
Then, the data you are looking for is in myobject.data.
Look here for more example code on JSON.parse.
I am trying to cast the content of my FormGroup value into an interface which I want use for posting something to my Web Api.
My interface looks like this:
export interface MoneyItemI {
Description: string;
Amount: number;
}
My submit methods looks like this:
onSubmit() {
let jsonString = JSON.stringify(this.itemForm.value);
let mi = <MoneyItemI>JSON.parse(jsonString);
}
I can see that I get an object created with JSON.parse but unfortunately it does not look like it an valid MoneyItemI object for me.
Property 'Amount' for example is not a number. It is assigned like a string.
How can I create a valid interface with the value of my FormGroup?
Does this.itemForm.value have the correct Amount and Description properties before you call JSON.stringify(this.itemForm.value)?
If so, you should be able to just do:
let mi = <MoneyItemI>this.itemForm.value;