AngularJS怎么在Node.js中使用-创新互联
本篇文章给大家分享的是有关AngularJS怎么在Node.js中使用,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
成都创新互联长期为上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为香坊企业提供专业的成都网站设计、成都网站制作,香坊网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。AngularJS是什么
AngularJS其实就是一个js库,一个js文件,帮助我们更好的开发Web前端。在github上,AngularJS这么介绍自己:
AngularJS lets you write client-side web applications as if you had a smarter browser. It lets you use good old HTML (or HAML, Jade and friends!) as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. It automatically synchronizes data from your UI (view) with your JavaScript objects (model) through 2-way data binding. To help you structure your application better and make it easy to test, AngularJS teaches the browser how to do dependency injection and inversion of control.
Oh yeah and it helps with server-side communication, taming async callbacks with promises and deferreds. It also makes client-side navigation and deeplinking with hashbang urls or HTML5 pushState a piece of cake. Best of all?? It makes development fun!
都是英文的,Are u OK?
按我的理解,这几点是比较重要的:
扩展HTML语法,动态修改HTML
双向数据绑定
提供针对前端和后端的各种服务,比如http,http,cookie,window,window,timeout,$document等,方便开发者
还有很多基于AngularJS的UI库,帮助我们构建复杂的Web UI,比如https://github.com/angular-ui或https://github.com/angular-ui/bootstrap。
AngularJS的学习资源
很多,Google或百度吧。另外推荐:https://github.com/jmcunningham/AngularJS-Learning。
也有很多专门讲AngularJS开发的图书,不过我没看过。我看的是《Node.js+MongoDB+AngularJS Web开发》,我觉得蛮不错的,涵盖了MEAN(Node.js-Express-AngularJS-MongoDB)技术栈,是想用一种语言成就全栈工程师梦想的不错选择。
在Node.js中支持AngularJS
AngularJS是一个客户端的JavaScript库,要想在Node.js里支持它,只要在HTML模板中嵌入script标记,让客户端能获取到angular.js文件就成了。
比如这样:
[code][/code]
但这基本上是死路一条,因为国内Google不通啊。所以,最好是翻qiang或VPN下载下来,部署到你的网站上,然后这样:
在HTML文档中使用AngularJS
这基本上分为四个部分:
使用ng-app指令定义应用程序模块
加载在script标签中定义的angular.js库
在HTML文档里插入angular相关的指令(directive)
实现控制器(一般在一个js文件里)
下面是一个使用AngularJS的HTML文档:
Node.js + Express + AngularJS Favorite Frameworks:
{{framework}}