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;    
}

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

#local variable внутри *ngIf

Представлены 2 варианта решения, как сослаться на локальную переменную шаблона (#myVar) за пределами шаблона:

  • @ViewChild
  • @ViewChildren
12 февраля 2019 г. в Angular