MVC是一种使用 MVC(Model View Controller 模型-视图-控制器)设计模式,该模型的理念也被许多框架所吸纳,好比,后端框架(Struts、Spring MVC等)、前端框架(Angular、Backbone等)。在学习angular的过程当中,我在网上查找关于angular MVC介绍的文章不多,有些文章也没有很直白地为初学者指明angular MVC究竟是啥样貌,所以,今天咱们就来谈谈MVC模型在angular的形态。css
为了介绍angular MVC模型,我创建一个最简单的例子。该例子的启动展现结果为:html
下面我会逐一解释。前端
view指的是视图,在web前端工程中,view每每指的是HTML代码。java
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/bootstrap.css" type="text/css">
</head>
<body ng-app="app">
<div class="col-md-4 col-md-offset-4" ng-controller="InputController">
模型数据: <input type="text" class="text-primary" ng-model="book.title">
</div>
<script src="js/angular.js"></script>
<script src="js/demo1.js"></script>
</body>
</html>
var book = {
title: "angular"
}
angular.module("app", ["InputModule"]);
angular.module("InputModule", [])
.controller("InputController", ["$scope", function ($scope) {
var book = {
title: "angular"
}
$scope.book = book;
}]);