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

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

@Attribute() декоратор

Аналогично @Input() позволяет получить значение атрибута с хоста компонента/директивы, но не отслеживает дальнейшее изменение атрибута.

14 сентября 2019 г. в Angular

Об subscribe() vs async

О предпочтительности использования async pipe. При OnPush стратегии не требуется вызывать markForCheck() внутри подписки +решение с несколькими | async pipes развёрнутых в одну переменную (внутри шаблона).

05 января 2019 г. в Angular

Angular routerLink conditionally

<a [routerLink]="myVar ? '/home' : null" routerLinkActive="is-active">Home</a>
or
<a [routerLink]="myVar ? ['/home'] : []">Home</a>
02 сентября 2019 г. в Angular

Angular Let Directive

*ngIf не отображает содержимое в falsy случаях (0, null, undefined) на async pipe, в пакете @rx-angular/template предлагается решение

27 сентября 2020 г. в Angular