AngularJS是什么
先标明来源:
https://code.angularjs.org/1.3.15/docs/guide/introduction
也就是官网针对1.3.15版的说明
What Is Angular?
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. Angular’s data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
AngularJS是一种用于开发动态页面APP的结构化框架。
通过它,你可以清晰明了地以HTML为基础,扩展其语法,来表达(标记?)界面上的组件。
AngularJS的数据绑定和依赖注入可以帮你省去很多繁琐的代码。
而且所有这些都运行在浏览器中,从而可以完美地跟任何服务器端技术相结合。
需要提前了解的概念:
1. web app:
A web application or web app is any computer program that runs in a web browser.
电脑程序放在浏览器里。
为什么要放在浏览器里?
浏览器全世界通用,但不灵活;
电脑程序灵活(跟用户交互多),但不通用。
所以把电脑程序放在浏览器里,其实就是对浏览器里的页面有高要求,要求像程序一样,呼风唤雨,要啥有啥。
所以,AngularJS就是把“在浏览器里呼风唤雨,要啥有啥”的要求给满足了的工具(框架)。
2. HTML:Hypertext Markup Language
Hypertext: Hypertext is text displayed on a computer display or other electronic devices with references to other text which the reader can immediately access, or where text can be revealed progressively at multiple levels of detail. (wikipedia)
超文本,就是在显示器上显示的文本,这种文本还要带有类似<a>一样的功能,就是一点就能看其他文本,或者一点一点一点就能看其他文本。
HTML is the standard markup language used to create web pages.
Web browsers can read HTML files and render them into visible or audible web pages. Browsers do not display the HTML tags and scripts, but use them to interpret the content of the page. (wikipedia)
HTML是用来创建页面的标准标记语言。
a> HTML是创建web page(页面)的;
b> HTML是标准;(大家都用,所以你用别的就不太好。不过如果哪天标准变了,不过是另一个标准,看看说明书,也就好了,不用太恐慌)
c> HTML是标记语言,就是按照人家的规则,简单标记一下你的页面上,什么内容当标题(title,h1, h2, ...),什么内容要严重显示(strong什么的)
浏览器干嘛:浏览器读入HTML,按照你根据标准写的标记,来完成展示。(别问我展示干嘛,我想静静。)
然后,HTML里的标签(就是标记)和脚本就不展示了。(你见过演讲的人把“停顿,微笑”和“此处应该有掌声”念出来的吗?)
3. application:应用
computer software designed to help the user to perform specific tasks. (wikipedia)
application就是应用,什么是应用,帮助用户完成特定任务,功能的软件。这不就是软件吗?(手机APP就是application的缩写吧?)
4. data binding:数据绑定
Data binding is the process that establishes a connection between the application UI and business logic. (wikipedia)
数据绑定,就是在应用界面和业务逻辑之间建立连接的过程。简单说,就是逻辑里是啥,你就看到啥,你看到的改成了啥,逻辑里就跟着变成了啥。(双向的数据绑定)
5. dependency injection:依赖注入
Dependency injection (DI) is a design pattern where dependencies are defined in an application as part of the configuration.(OReilly Learning AngularJS 2015-3)
依赖注入(DI)就是一个把依赖(没谁就不能运行)定义成配置的设计模式(设计模式就是设计的时候大家都觉得好的办法)。
Angular is what HTML would have been, had it been designed for applications. HTML is a great declarative language for static documents. It does not contain much in the way of creating applications, and as a result building web applications is an exercise in what do I have to do to trick the browser into doing what I want?
如果HTML最初是朝着应用的方向设计的,那它肯定就变成了AngularJS这样子。对静态文档而言,HTML是一个强大的声明式语言,不过它并不包含太多创建应用的东西。所以创建web app就变成了这样:我怎么让浏览器按照我的需要来工作呢?
The impedance mismatch between dynamic applications and static documents is often solved with:
- a library - a collection of functions which are useful when writing web apps. Your code is in charge and it calls into the library when it sees fit. E.g. jQuery.
- frameworks - a particular implementation of a web application, where your code fills in the details. The framework is in charge and it calls into your code when it needs something app specific. E.g. durandal, ember, etc.
动态应用和静态文档之间的不搭嘎的阻力,一般情况下是这样解决的:
- 库: 就是一套可调用的函数,你的代码做东,需要调谁就调谁。比如,jQeury.
- 框架:专门为web app开发的空架子,你只需要用自己的代码把里面的细节填一下就可以了。这样,就是框架做东,处理大部分的事,适当的情况下从你的代码里拉它需要的内容(配置,逻辑神马的)。比如durandal和ember。
Angular takes another approach. It attempts to minimize the impedance mismatch between document centric HTML and what an application needs by creating new HTML constructs. Angular teaches the browser new syntax through a construct we call directives.
Examples include:
- Data binding, as in {{}}.
- DOM control structures for repeating, showing and hiding DOM fragments.
- Support for forms and form validation.
- Attaching new behavior to DOM elements, such as DOM event handling.
- Grouping of HTML into reusable components.
AngularJS跟他们还不一样。它通过创建新的HTML概念来降低将以文档为中心的HTML和实际应用程序所需调合在一起的阻力。AngularJS通过这种新概念增加浏览器能解析的HTML新语法,这一概念,我们称之为directive。(指令)
新语法的例子:
- 数据绑定的语法:{{}}
- 重复,显示,隐藏DOM片段的DOM控制结构;
- form(表单)支持和校验;
- 向DOM元素添加行为,比如DOM消息处理;
- 把HTML包装成可复用的组件。
A complete client-side solution
Angular is not a single piece in the overall puzzle of building the client-side of a web application. It handles all of the DOM and AJAX glue code you once wrote by hand and puts it in a well-defined structure. This makes Angular opinionated about how a CRUD (Create, Read, Update, Delete) application should be built. But while it is opinionated, it also tries to make sure that its opinion is just a starting point you can easily change. Angular comes with the following out-of-the-box:
- Everything you need to build a CRUD app in a cohesive set: Data-binding, basic templating directives, form validation, routing, deep-linking, reusable components and dependency injection.
- Testability story: Unit-testing, end-to-end testing, mocks and test harnesses.
- Seed application with directory layout and test scripts as a starting point.
Angular不是创建客户端web app的解决方案里的一部分(它是全套解决方案),它可以接管你写的全部DOM和AJAX操作代码,而且组织还特别合理。这让Angular在app处理CRUD(增删改查,你懂的)上很顽固(翻译得好牵强)。好在,Angular也尽量把DOM和AJAX操作做得简单和可修改。Angular自带以下开箱即用特性:
- 所有要处理CRUD的工具:数据绑定,基本模板指令(就是前面提到的教给浏览器的新HTML语法),表单验证,跳转,deep-linking,可复用组件和依赖注入。
- 可测场合:单元测试,系统测试,模拟和测试仪。
- (原谅我无能,看不懂啥意思)
deep-linking:
In the context of the World Wide Web, deep linking consists of using a hyperlink that links to a specific, generally searchable or indexed, piece of web content on a website, rather than the home page. (这个懒得翻了,学软件总难免看英文的。详见wikipedia)
end-to-end testing: System testing.(wikipedia)
Mock object:
In object oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts. 模拟,就是汽车撞击试验中的假人。啥都像真的,就是是假的。
Angular’s sweet spot
Angular simplifies application development by presenting a higher level of abstraction to the developer. Like any abstraction, it comes at a cost of flexibility. In other words, not every app is a good fit for Angular. Angular was built with the CRUD application in mind. Luckily CRUD applications represent the majority of web applications. To understand what Angular is good at, though, it helps to understand when an app is not a good fit for Angular.
Games and GUI editors are examples of applications with intensive and tricky DOM manipulation. These kinds of apps are different from CRUD apps, and as a result are probably not a good fit for Angular. In these cases it may be better to use a library with a lower level of abstraction, such as jQuery.
Angular哪儿甜?(什么情况下使用Angular会尝到甜头?)
Angular通过更高的抽象简化了web app的开发。每种高层抽象都会降低灵活性。所以Angular也不是一切web app通吃的。Angular的初衷,就是要做CRUD。好在,市面上的web app基本大多也只是个增删改查(哦呵呵)。那什么时候用Angular呢?还是说说什么时候不该用它吧。
比方说你要开发游戏,或者你要大改UI,这些需要N多操纵DOM。它们就跟CRUD应用不一样了吧,那你就不要用Angular了。这种情况下,建议还是用点更底层的库,比如jQuery.
The Zen of Angular
Angular is built around the belief that declarative code is better imperative when it comes to building UIs and wiring software components together, while imperative code is excellent for expressing business logic.
It is a very good idea to decouple DOM manipulation from app logic. This dramatically improves the testability of the code.
It is a really, really good idea to regard app testing as equal in importance to app writing. Testing difficulty is dramatically affected by the way the code is structured.
It is an excellent idea to decouple the client side of an app from the server side. This allows development work to progress in parallel, and allows for reuse of both sides.
It is always good to make common tasks trivial and difficult tasks possible.
Angular之禅
Angular信奉这样的理念:声明式语言更适合写界面,命令式语言更适合处理业务逻辑。
将DOM操纵和app逻辑分隔开,是灰常好滴。这会大幅度提高可测试性。
视测试与开发同等重要也是灰常灰常好滴。Angular组织代码的形式也大幅度提高了测试的简易度。
客户端和服务器端相互独立,更是灰常灰常好滴。这样就可以同时开发,也便于复用。
灰常灰常好滴,比如一般问题变脑残,复杂问题变可能。
Angular frees you from the following pains:
- Registering callbacks:Registering callbacks clutters your code, making it hard to see the forest for the trees. Removing common boilerplate code such as callbacks is a good thing. It vastly reduces the amount of JavaScript coding you have to do, and it makes it easier to see what your application does.
- Manipulating HTML DOM programmatically: Manipulating HTML DOM is a cornerstone of AJAX applications, but it's cumbersome and error-prone. By declaratively describing how the UI should change as your application state changes, you are freed from low-level DOM manipulation tasks. Most applications written with Angular never have to programmatically manipulate the DOM, although you can if you want to.
- Marshaling data to and from the UI: CRUD operations make up the majority of AJAX applications' tasks. The flow of marshaling data from the server to an internal object to an HTML form, allowing users to modify the form, validating the form, displaying validation errors, returning to an internal model, and then back to the server, creates a lot of boilerplate code. Angular eliminates almost all of this boilerplate, leaving code that describes the overall flow of the application rather than all of the implementation details.
- Writing tons of initialization code just to get started: Typically you need to write a lot of plumbing just to get a basic "Hello World" AJAX app working. With Angular you can bootstrap your app easily using services, which are auto-injected into your application in a Guice-like dependency-injection style. This allows you to get started developing features quickly. As a bonus, you get full control over the initialization process in automated tests.
使用Angular,你就可以远离烦恼,实现以下梦想:
- 不必自己注册回掉函数;
- 更有组织性地操纵DOM;
- 从/到UI的数据整顿起来;(组织更好)
- 不必为写逻辑先写N多废话。
AngularJS是什么的更多相关文章
- 通过AngularJS实现前端与后台的数据对接(二)——服务(service,$http)篇
什么是服务? 服务提供了一种能在应用的整个生命周期内保持数据的方法,它能够在控制器之间进行通信,并且能保证数据的一致性. 服务是一个单例对象,在每个应用中只会被实例化一次(被$injector实例化) ...
- AngularJs之九(ending......)
今天继续angularJs,但也是最后一篇关于它的了,基础部分差不多也就这些,后续有机会再写它的提升部分. 今天要写的也是一个基础的选择列表: 一:使用ng-options,数组进行循环. <d ...
- AngularJS过滤器filter-保留小数,小数点-$filter
AngularJS 保留小数 默认是保留3位 固定的套路是 {{deom | number:4}} 意思就是保留小数点 的后四位 在渲染页面的时候 加入这儿个代码 用来精确浮点数,指定小数点 ...
- Angular企业级开发(1)-AngularJS简介
AngularJS介绍 AngularJS是一个功能完善的JavaScript前端框架,同时是基于MVC(Model-View-Controller理念的框架,使用它能够高效的开发桌面web app和 ...
- 模拟AngularJS之依赖注入
一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...
- 步入angularjs directive(指令)--点击按钮加入loading状态
今天我终于鼓起勇气写自己的博客了,激动与害怕并存,希望大家能多多批评指导,如果能够帮助大家,也希望大家点个赞!! 用angularjs 工作也有段时间了,总体感觉最有挑战性的还是指令,因为没有指令的a ...
- 玩转spring boot——结合AngularJs和JDBC
参考官方例子:http://spring.io/guides/gs/relational-data-access/ 一.项目准备 在建立mysql数据库后新建表“t_order” ; -- ----- ...
- 玩转spring boot——结合jQuery和AngularJs
在上篇的基础上 准备工作: 修改pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...
- 通过AngularJS实现前端与后台的数据对接(一)——预备工作篇
最近,笔者在做一个项目:使用AngularJS,从而实现前端与后台的数据对接.笔者这是第一次做前端与后台的数据对接的工作,因此遇到了许多问题.笔者在这些问题中,总结了一些如何实现前端与后台的数据对接的 ...
- AngularJS 系列 学习笔记 目录篇
目录: AngularJS 系列 01 - HelloWorld和数据绑定 AngularJS 系列 02 - 模块 (持续更新)
随机推荐
- HashTable 简述
1.解释:使用了映射函数,把值映射到对应的位置,key-> address, address是表中的存储位置,不是实际的地址: 2.Hash 函数设计, 分布合理,冲突少,利用率平衡,利用率 ...
- i2c协议简要分析(转载)
声明 本文大部分内容为转载,因此标定为转载 源地址: http://www.cnblogs.com/zym0805/archive/2011/07/31/2122890.html http://blo ...
- java io流之字符流
字符流 在程序中一个字符等于两个字节,那么java提供了Reader.Writer两个专门操作字符流的类. 字符输出流:Writer Writer本身是一个字符流的输出类,此类的定义如下: publi ...
- 生成SSH key
1.打开终端 2.输入cd ~/.ssh 3.输入ssh-keygen -t rsa -C (邮箱) 4.前往文件夹 /Users/admin/.ssh/id_rsa 5.找到id_rsa.pub , ...
- 安卓app中嵌入一个H5页面,当手机系统设置字体变大时,如何使H5页面的字体不会随用户自己调整的系统字体变化而变化?
webview.getSettings().setTextZoom(100);WebView加上这个设置后,WebView里的字体就不会随系统字体大小设置发生变化了. https://segmentf ...
- curl 模拟登录微信公众平台带验证码
这段时间一直写个项目, 从切图到前端到后台都要搞定,真tm累. 今天下午手残,不停用错误的密码去模拟登录微信公众平台,结果后来出现验证码,瞬间悲剧(菜鸟从来没搞过带验证码的). 研究了一下,发现其实很 ...
- myeclipse10的激活
myeclipse 提醒了我好几天要激活,今天操作了下,出现的问题分享一下. 在激活工具里面没有找到cracker.jar,按照指导双击run.bat,但是打开之后闪一下就自动关闭了,不得其解.然后搜 ...
- 反射,System.Type类
http://m.blog.csdn.net/blog/woddle/40623333 两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏的生理情况.这是如何做到 ...
- 苗子sale record
2016年7月11日 橘白/阳光 发广州 220 中通 719373064939 成功2016年7月11日 横纹RA 发潮州 250 中通 719373064940 成功2016年7月18日 ...
- Cookie的Secure属性
基于安全的考虑,需要给cookie加上Secure和HttpOnly属性,HttpOnly比较好理解,设置HttpOnly=true的cookie不能被js获取到,无法用document.cookie ...