about 9 years ago
Model View Controller is abbreviated as MVC. MVC is the popular web design architecture because it separates the business logic from its view or presentation.
It has three components:-
Now, lets understand how these components works in AngularJS MVC architecture-
1.Model - It contains all the data(primitive data types and in the form of objects). It interacts with local database and backend JSON. For example:-
In the above example webseries is a variable which is added to the object($scope).
2.View - It is the presentation of the data that the model contains. In Angular we use expressions to display the data from the controller. It is simply the manipulation of the DOM elements to display the data. For example:-
3.Controller - In Angular controller controls the flow of data into model object and updates the view whenever data changes. It keeps the view and model separate. It provides great controller as to displaying of data in the view according to the request. For example:-
The complete code will look like this:-
<html ng-app=myApp">
<head>
<title> AngularJS MVC Architecture small example</title>
<script src="js/angular.min.js"></script>
</script>
<script type="text/javascript">
//Creating controller here
var app = angular.module(myApp', []);
app.controller('Worldwebseries', function($scope) {
//Creating model here
$scope.webseries = {
ShowName' : TVF Pitchers,
Channel : TVF Play,
ImdbRating : 22
}
});
</script>
</head>
<body>
<p>Displing model data in view through controller</p>
<div ng-controller="Worldwebseries">
<p>{{webseries.ShowName}}</p>
<p>{{webseries.Channel}}</p>
<p>{{webseries.ImdbRating}}</p>
</div>
</body>
</html>
<html ng-app=myApp">
<head>
<title> AngularJS MVC Architecture small example</title>
<script src="js/angular.min.js"></script>
</script>
<script type="text/javascript">
//Creating controller here
var app = angular.module(myApp', []);
app.controller('Worldwebseries', function($scope) {
//Creating model here
$scope.webseries = {
ShowName' : TVF Pitchers,
Channel : TVF Play,
ImdbRating : 22
}
});
</script>
</head>
<body>
<p>Displing model data in view through controller</p>
<div ng-controller="Worldwebseries">
<p>{{webseries.ShowName}}</p>
<p>{{webseries.Channel}}</p>
<p>{{webseries.ImdbRating}}</p>
</div>
</body>
</html>
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)