3

I've got many links which introduce MVC, MVP, MVVM and so on. But I didn't get one which tells what M exactly stands for in Angular2, what V exactly stands for in Angular2 and what W exactly stands for in Angular2. Maybe there is an answer for W. That is W stands for whatever.

Can anyone help me with the following example.

AppModule:

import { NgModule }           from '@angular/core';
import { BrowserModule }      from '@angular/platform-browser';

import { AppComponent }       from './app.component';
import { AppService }        from './app.service';


@NgModule({
  imports:      [
    BrowserModule
  ],
  providers:    [ AppService ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

AppComponent:

import { Component } from '@angular/core';
import { AppService }        from './app.service';
import { Message }        from './message';

@Component({
  selector: 'my-app',
  template: '<h1>{{message.body}}</h1>from<h2>{{message.sender}}</h2>',
})
export class AppComponent {
  private message: Message;

  constructor(appService: AppService) {
    this.message = userService.getMessage();
  }
}

Message:

export class Message {
  private body: string;
  private sender: string;

  constructor() {
    this.body = 'hello, world';
    this.sender = 'Lcng';
  }
}

AppService:

import { Injectable } from '@angular/core';
import { Message }        from './message';

@Injectable()
export class AppService {
  getMessage(): Message{
    let message = new Message();
    return message;
  }
}

So my understanding is:

M (of course it stands for Model) is the Domain Model. And in the above example the Domain Module is the AppService. So most of the time M is the services(except something like utility services).

V is View, which is rendered by a Component's template. In the above example V is the greeting screen.

W is whatever. And it is the Component which looks like a Controller, a ViewModel, and a whatever..

And, the class Message in the above example is a Entity Model which is not the M..

So am I right? Could you help me please..

Lcng
  • 706
  • 1
  • 8
  • 17

1 Answers1

2

AppComponent class is equivalent to the controller class and is thus your W.

view is the components HTML

model is the services that can be provided / injected.

danday74
  • 52,471
  • 49
  • 232
  • 283
  • 1
    Why "W" though? –  Nov 25 '16 at 11:35
  • 1
    W stands for whatever ... initially it was called C for controller, then it was called VM for View Model (the thing that binds the view and the model together), finally they changed it to W for Whatever ... e.g. I dont care if you want to call it a controller or a view model - I just want to refer to the thing that binds the view and the model and what you call it is irrelevant – danday74 Nov 25 '16 at 11:38