Reputation: 341
After having to learn MVC when I recently dove into angular, I was having trouble with the concept before I even tried to code. Now that i've spent a few weeks using angular, I think I have MVC down.
The representation of your data. Its the variables that your module has.Colour = blue
.
This data is then displayed in the
The display of your data. The physical HTML.
<div>{{colour}}</div>
This value is updated by the
The controller doesn't have to be the literal .controller
it could be a directive, factory, or a filter. As long as it helps or changes the display of data to the view or vice versa, like in the case of the controller, it doesn't matter.
Is this a correct way of thinking when it comes to MVT? If not, why?
Upvotes: 1
Views: 2301
Reputation: 85545
Like other frameworks, Angularjs also has MVC pattern. And yes it should not be just .controller to be the controller in MVC pattern.
The Model: (eg:- ng-model directive)
The directive is the model here.
<p>Enter your Name: <input type = "text" ng-model = "name"></p>
The View: (eg:- ng-bind directive)
The directive is the view here.
<p>Hello <span ng-bind = "name"></span>!</p>
The Controller: (The code which will control the model and the view)
So, the method used in angularjs as an example of using .directive is not restricted to the view or the model. It could be the controller in the MVC pattern. Thus, it matters the reflection of your coding behavior.
Furthermore, you may call it MVW (Model View Whatever):
Read more about angularjs superheroic javascript framework.
Upvotes: 3
Reputation: 1694
Yes, it seems you are right. Just want to add one point regarding view
. Normal HTML
in AngularJS called template. Angular processes markup using compiler. The loaded, transformed and rendered DOM
is then called the view.
Upvotes: 0