Benefit of defining model class in angular2+
up vote
-2
down vote
favorite
While creating service for my domain i realized i can simply implement service using any type like this :
list(): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: any): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
instead of explicitly mentioning Class like this :
list(): Observable<Car> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: Car): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
I know the the second one is correct way and better aproach(while in first way we can save time with less file making and no commitment to properties) but what exactly we benefit from defining model classes and it's properties in Angular ?
it was supposed to keep Model as simple as it is possible in MVC.
angular typescript
add a comment |
up vote
-2
down vote
favorite
While creating service for my domain i realized i can simply implement service using any type like this :
list(): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: any): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
instead of explicitly mentioning Class like this :
list(): Observable<Car> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: Car): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
I know the the second one is correct way and better aproach(while in first way we can save time with less file making and no commitment to properties) but what exactly we benefit from defining model classes and it's properties in Angular ?
it was supposed to keep Model as simple as it is possible in MVC.
angular typescript
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
While creating service for my domain i realized i can simply implement service using any type like this :
list(): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: any): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
instead of explicitly mentioning Class like this :
list(): Observable<Car> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: Car): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
I know the the second one is correct way and better aproach(while in first way we can save time with less file making and no commitment to properties) but what exactly we benefit from defining model classes and it's properties in Angular ?
it was supposed to keep Model as simple as it is possible in MVC.
angular typescript
While creating service for my domain i realized i can simply implement service using any type like this :
list(): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: any): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
instead of explicitly mentioning Class like this :
list(): Observable<Car> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.get(url, { headers: this.header });
}
add(item: Car): Observable<any> {
const url = this.appUrlApi + this.serviceUrlApi;
return this.http.post(url, item, { headers: this.header });
}
I know the the second one is correct way and better aproach(while in first way we can save time with less file making and no commitment to properties) but what exactly we benefit from defining model classes and it's properties in Angular ?
it was supposed to keep Model as simple as it is possible in MVC.
angular typescript
angular typescript
edited Nov 21 at 16:43
asked Nov 21 at 16:41
ghazyy
147313
147313
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
You're effectively asking, "why use strong typing" since this isn't Angular specific.
In a word: scalability. The bigger the program, the greater likelihood of mistakes. Types narrow down the what could possibly be going wrong.
add a comment |
up vote
1
down vote
Easier debugging would be one thing that comes to mind. You'll then know when your double gets filled with a String.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You're effectively asking, "why use strong typing" since this isn't Angular specific.
In a word: scalability. The bigger the program, the greater likelihood of mistakes. Types narrow down the what could possibly be going wrong.
add a comment |
up vote
2
down vote
accepted
You're effectively asking, "why use strong typing" since this isn't Angular specific.
In a word: scalability. The bigger the program, the greater likelihood of mistakes. Types narrow down the what could possibly be going wrong.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You're effectively asking, "why use strong typing" since this isn't Angular specific.
In a word: scalability. The bigger the program, the greater likelihood of mistakes. Types narrow down the what could possibly be going wrong.
You're effectively asking, "why use strong typing" since this isn't Angular specific.
In a word: scalability. The bigger the program, the greater likelihood of mistakes. Types narrow down the what could possibly be going wrong.
answered Nov 21 at 17:14
Ron Newcomb
1,030814
1,030814
add a comment |
add a comment |
up vote
1
down vote
Easier debugging would be one thing that comes to mind. You'll then know when your double gets filled with a String.
add a comment |
up vote
1
down vote
Easier debugging would be one thing that comes to mind. You'll then know when your double gets filled with a String.
add a comment |
up vote
1
down vote
up vote
1
down vote
Easier debugging would be one thing that comes to mind. You'll then know when your double gets filled with a String.
Easier debugging would be one thing that comes to mind. You'll then know when your double gets filled with a String.
answered Nov 21 at 17:10
Nikolai Kiefer
1618
1618
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416782%2fbenefit-of-defining-model-class-in-angular2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown