Disclaimer: Seeking insight on the correct approach or any additional information
_____________________________________________________________________
ANGULAR1
When working with angular1
, we had the option to define our objects in the following manner.
$scope.user={};
$scope.user.name="micronyks";
$scope.user.age="27";
Alternatively, we could directly assign values like this:
$scope.user={name:"micronyks",age:"27"}
The binding to the template would appear as follows:
<div>My name is {{user.name}} & I'm {{user.age}} year(s) old. </div>
______________________________________________________________________
ANGULAR2
In angular2 using Typescript,
models.ts
export class LoginModel()
{
private name:string;
private age:number;
}
app.ts
import {LoginModel} from '../models.ts';
user=new LoginModel()
constructor()
{
this.user.name="micronyks"
this.user.age="27"
}
app.html
<div>My name is {{user.name}} & I'm {{user.age}} year(s) old. </div>
Is it possible to directly create an object with properties and values?
I understand that TypeScript
primarily deals with types
.
If anyone has profound insights on this subject matter, please enlighten me further.
To showcase something, feel free to use this plunker: Plunker