Angular & MVVM

Model

Just file like user.class.ts

class User {
  name:string;
  email:string;
  address:string;
}

View

HTML template user.component.html of component

<main>
  <h3>{{ user.name }}</h3>
  <p>{{ user.email }}</p>
  <p>{{ user.address }}</p>
</main>

ViewModel

Typescript part of a component

@Component({
    selector:"app-user",
    templateUrl:"./user.component.html",
    styleUrls: ["./user.component.css"]
    providers: [UserService]
})
export class UserComponent implements OnInit {
  @Input()
  user: User;    
}

Похожие записи