1.AngularJS

一个构建动态Web应用程序的结构化框架。

基于JavaScript的MVC框架。(  MVC ---- Model(模型)、View(视图)、Controller(控制器) )

主要作用:

1)简化复杂Web应用的开发难度

a) MVC程序架构,解耦应用逻辑、数据模型和视图

b) 数据绑定

c) 依赖注入

d) Ajax服务

2)提高应用程序的可测试性、可维护性

擅长领域:

1)单页面应用程序Single Page Application(SPA)

2)CRUD程序

下载和使用

官网:http://angularjs.org

中文网:http://www.angularjs.cn

文档:http://docs.angularjs.cn/api

AngularJS的使用:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="KunShan Online retailers ">
<title></title> <link rel="stylesheet" href="css/angular-csp.css" />
</head>
<body> <script type="text/javascript" src="js/angular.js" ></script>
</body>
</html>

2.Module:模块

创建方式:angular.module(‘myApp’,[]);

使用模块的好处:

1)保持全局命名空间的清洁;

2)编写测试代码更容易;

3)易于在不同的应用程序之间复用代码。

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="KunShan Online retailers ">
<title></title> <link rel="stylesheet" href="css/angular-csp.css" />
</head>
<body ng-app='myApp'>
<!--
ng-app : Angularjs的模块,也可以理解为AngularJS的作用域
-->
<h3>{{"hello"}}</h3> <script type="text/javascript" src="js/angular.js" ></script>
<script type="text/javascript" src="js/index.js" ></script> </body>
</html>
var app = angular.module('myApp',[]);//创建的模块赋值给app对象

3.Controller和scope

控制器:在AngularJS中控制器是一个函数,用来向视图的作用域添加额外的功能,用来设置作用域的初始状态并添加自定义行为。

控制器的声明:

app.controller(‘controllerName’,function($scope){...}) //app对象是angularJs定义好的模块

控制器的使用:

在需要的地方(html某个标签上)添加ng-controller

使用控制器注意事项:

1)尽可能精简控制器,制作和$scope相关的操作

2)不适合在控制其中执行DOM操作、格式化或数据操作。

控制器的嵌套

控制器之间可以发生嵌套关系,子控制器可以访问父控制器中的属性和方法。

代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="KunShan Online retailers ">
<title></title> <link rel="stylesheet" href="css/angular-csp.css" />
</head>
<body ng-app='myApp' ng-controller='myController'>
<!--
ng-app : angularjs的模块
ng-controller :控制器的使用
-->
<h3>{{"hello"}}</h3>
<button ng-click='add()'>Test</button><!--ng-click:点击事件-->
<h4>{{num}}</h4> <div ng-controller='myController2'><!--myController2嵌套在myController中-->
<button ng-click='add()'>Test,myController2</button>
<span>{{num}}</span>
</div> <script type="text/javascript" src="js/angular.js" ></script>
<script type="text/javascript" src="js/index.js" ></script> </body>
</html>
var app = angular.module('myApp',[]);//创建的模块赋值给app对象

//controller  $scope:作用域对象
app.controller('myController',function($scope){
$scope.num=0;//视图中的num变量 //add方法 视图中的add()
$scope.add=function(){
$scope.num++;
};
}); app.controller('myController2',function($scope){ });

AngularJS-01.AngularJS,Module,Controller,scope的更多相关文章

  1. 33.AngularJS 应用 angular.module定义应用 angular.controller控制应用

    转自:https://www.cnblogs.com/best/tag/Angular/ AngularJS 模块(Module) 定义了 AngularJS 应用. AngularJS 控制器(Co ...

  2. AngularJS中Directive指令系列 - scope属性的使用

    文章是转的,我做下补充.原文地址:https://segmentfault.com/a/1190000002773689 每当一个指令被创建的时候,都会有这样一个选择,是继承自己的父作用域(一般是外部 ...

  3. JavaScript文件中调用AngularJS内部方法或改变$scope变量

    需要在其他JavaScript文件中调用AngularJS内部方法或改变$scope变量,同时还要保持双向数据绑定: 首先获取AngularJS application: 方法一:通过controll ...

  4. 【AngularJS】AngularJS 教程

    AngularJS通过新的属性和表达式扩展了HTML.------------->扩展HTML属性 AngularJS可以构建一个单页面应用程序(SPAs: Single Page Applic ...

  5. Module controller in JMeter

    https://qualibrate.com/blog/quality-assurance/jmeter-module-controller/ 通过组合Test Fragments 和Module C ...

  6. Jmeter(十九)Logic Controllers 之 Module Controller and Include Controller

    Module Controller ---模块控制器 测试计划设置“独立运行没每个线程组” 线程组2中使用Module Controller执行线程组1中的Sampler: 紧接着,将线程组1disa ...

  7. Jmter-Test Fragment、Include Controller和Module Controller

    Test Fragment--测试片段 The Test Fragment is used in conjunction with the Include Controller and Module ...

  8. jmeter的Include Controller控件和Test Fragment控件和Module Controller控件

    1.Include Controller控件——给当前jmeter脚本引入外部片段的jmeter脚本(Test Fragment片段脚本) Include Controller控件——添加外部jmet ...

  9. Jmeter (二十六)逻辑控制器 之 Module Controller and Include Controller

    Module Controller ---模块控制器 测试计划设置“独立运行没每个线程组” 线程组2中使用Module Controller执行线程组1中的Sampler: 紧接着,将线程组1disa ...

随机推荐

  1. Oracle JDBC 连接池

    1.简介 数据库连接池负责分配.管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个:释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据 ...

  2. np.random.choices的使用

    在看莫烦python的RL源码时,他的DDPG记忆库Memory的实现是这样写的: class Memory(object): def __init__(self, capacity, dims): ...

  3. PostgreSQL SELECT INTO和INSERT INTO SELECT 两种表复制语句

    SELECT INTO和INSERT INTO SELECT两种表复制语句都可以用来复制表与表之间的数据,但是它们之间也有区别. 建表语句: bas_custom_rel表 CREATE TABLE ...

  4. arcgis的arcpy写入几何怎么创建一个空心面要素并读取几何和属性信息,根本不够管

    转载请注明作者(独孤尚良dugushangliang)出处:https://blog.csdn.net/dugushangliang/article/details/83861447 这个我是没找到这 ...

  5. 安装Rabbitmq脚本

    安装RabbitMQ时需要先安装erlang插件 [root@ZHONG-LONG javascripts]# vim -erlang.sh #!/bin/sh ######安装erl插件 PRO=/ ...

  6. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_11-freemarker静态化测试-基于模板字符串静态化

    再定义一个测试方法 把拿到的字符串变成模板 加载器设置好了以后, 加一个断点来测试 生成模板文件 上面这种方式很灵活. 最终代码 @Test public void testGenerateHtmlB ...

  7. Spring Cloud(6):保护微服务(Security) - OAuth2.0

    OAuth2是一个授权(Authorization)协议.我们要和Spring Security的认证(Authentication)区别开来,认证(Authentication)证明的你是不是这个人 ...

  8. Sprint Retrospective - 回顾的重要性

    在Scrum中,每个Sprint结束的时候会有两个会议(Sprint Review/Demo和Sprint Retrospective回顾).这两个会议是对过去的一个Sprint的一个总结,其中Rev ...

  9. RMQ问题--ST

    #include<iostream> #include<cstdio> #include<cmath> using namespace std; ; ]; int ...

  10. 《精通并发与Netty》学习笔记(12 - 详解NIO (三) SocketChannel、Pipe)

    一.SocketChannelJava NIO中的SocketChannel是一个连接到TCP网络套接字的通道.可以通过以下2种方式创建SocketChannel: 打开一个SocketChannel ...