MVC:从计算机存储器中取出指令, 对指令进行译码, 并根据指令的要求, 按时间的先后顺序向各部件发出控制信号, 保证各部件协调一致地工作, 完成各种操作, 网页中使用MVC创建框架, 可以减少程序员的开发周期, 网页执行快, 逻辑性强, 下面我们就以Angular框架为例,创建一个Angular控件器 。 工具/材料 Angular框架
操作方法 01 【如何创建网页控制器MVC】打开编译环境(webstorm), 在工程文件夹里新建一个html文件
02 在ctrl.html文件夹引入所需要的包和工具, 如bootstrp和angular等
03 在angular.js文件下方定义一个angular模块(module), 代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href=https://vvvtt.com/article/"node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<script src=https://vvvtt.com/article/"node_modules/bootstrap/dist/js/bootstrap.min.js">
<script src=https://vvvtt.com/article/"node_modules/angular/angular.min.js">
<script>
var myapp =augular.module('myapp',[])//定义一个模块
</script>
</body>
</html>
04 定义一个控制器, 并用scope搭建视图与网页通信的桥梁, 代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href=https://vvvtt.com/article/"node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body>
<script src=https://vvvtt.com/article/"node_modules/bootstrap/dist/js/bootstrap.min.js">
<script src=https://vvvtt.com/article/"node_modules/angular/angular.min.js">
<script>
var myapp =augular.module('myapp',[])//定义一个模块
myapp.controller=("myctrl",['scrope',function () {
}])
</script>
</body>
</html>
05 在function随便定义一个变量, 一般为scope,网页头部<html>引入模块名:ng-app="myapp",在网页主体内容<body>里面引入控制器ng-controller="myctrl"这样, 网页的内容才能被MVC控制器所接收和识别, 代码如下:
<!DOCTYPE html>
<html lang="en" ng-app="myapp">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href=https://vvvtt.com/article/"node_modules/bootstrap/dist/css/bootstrap.min.css">
</head>
<body ng-app="ng-controller">
<script src=https://vvvtt.com/article/"node_modules/bootstrap/dist/js/bootstrap.min.js">
<script src=https://vvvtt.com/article/"node_modules/angular/angular.min.js">
<script>
var myapp =augular.module('myapp',[])//定义一个模块
myapp.controller=("myctrl",['scope',function (scope) {
猜你喜欢
- 上班族久坐腰痛如何来缓解?
- 教师如何让自己变得有耐心
- 苹果手机误删的照片如何恢复?
- 如何查询天天快递单号
- 手机支付宝钱包如何绑定银行卡?
- 如何解决err_connection_reset
- 注册中的商标如何申请撤销?
- 宝宝撞伤时如何紧急处理?
- 女权主义的发展历史是怎样的,我们应如何看待当代女权主义?
- 微信如何拉黑或取消拉黑
