First things first, this is my first time using Angular 7; I started making an application using Angular 7 with a c# back end and have need for serializing an object in my component/service
before sending it to my controller/service
.
Something like:
export class jsonTest {
json: string;
obj: myType = {} as myType;
this.obj.someProperty = 1234;
this.obj.anotherProperty = 'test';
someMethod() {
this.json = //convert obj to json
anotherMethod(this.json);
}
}
In my search to figure out how to accomplish this, I've come across two popular suggestions, one being JSON.stringify()
and another being toJson()
.
However, JSON.stringify()
throws a compile error that symbol JSON cannot be resolved, probably it is located in an inaccessible module.
Trying toJson()
, it isn't recognized as a hook of any sort.
Is there some import that I'm missing? Looking through angular documentation doesn't shed any light on my issue.
At this point, I'm considering just serializing the JSON manually, but I'd really like to avoid doing that if I can. Any suggestions?