Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Is it possible to import a model class(let's say product.cs) which is created in "Models" folder into the angular 2 application instead of creating the same fields under product.ts file and using it in the Asp.NET Core Angular 2 application?

Is there any solution for reusing the code instead of creating 2 classes with same fields?

What I have tried:

I have created a typescript file which consists of same fields which are available under model class(*.cs) and worked on the application.
Updated 31-Dec-16 5:11am

1 solution

You can also "not" import anything at all, and use dynamic types to get the values. Most of the times when you have no idea about the schema implementations on the server, then you can easily use these types instead of mimicking the types.

I wrote an article about JSON with C#, there this kind of question was asked, you can read more on that topic here, Re: How you will Deserialize this example? [^].

By dynamic, what I mean is to "skip" type checking, and defer it until the runtime and then access the objects if they are not null.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900