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?

按我的理解,这几点是比较重要的:

  1. 扩展HTML语法,动态修改HTML

  2. 双向数据绑定

  3. 提供针对前端和后端的各种服务,比如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

  1. 这基本上分为四个部分:

  2. 使用ng-app指令定义应用程序模块

  3. 加载在script标签中定义的angular.js库

  4. 在HTML文档里插入angular相关的指令(directive)

  5. 实现控制器(一般在一个js文件里)

下面是一个使用AngularJS的HTML文档:




 Node.js + Express + AngularJS


 
 

Favorite Frameworks:

 {{framework}}  
   

上面的文档内引用到的frameworks.js内容如下:

angular.module('myApp', []).
 controller('myController', ['$scope', function($scope){
 $scope.frameworks = ['Node.js', 'Express', 'AnjularJS'];
 }]);

把frameworks.html文件放在HelloExpress的public目录下面,把frameworks.js放在public/javascripts目录下,运行网站,在浏览器打开地址“http://localhost:3000/frameworks.html”,效果如下图所示:

AngularJS怎么在Node.js中使用

在jade模板中使用AngularJS

其实jade模板文件里使用AngularJS,只需要将Angular指令嵌入即可,没什么特别的。如果你有现成的html文档,也可以使用html转jade的在线工具来转换为jade模板文件,在这里:http://html2jade.org。

前面使用了AnjularJS的HTML文档,对应的jade模板文件frameworks.jade内容如下:

doctype html
html(ng-app="myApp")
 head
 title Node.js + Express + AngularJS
 body
 div(ng-controller="myController")
  h4 Favorite Frameworks:
  li(ng-repeat="framework in frameworks")
  {{framework}}

 script(src="/javascripts/angular-1.4.3.min.js")
 script(src="/javascripts/frameworks.js")

以上就是AngularJS怎么在Node.js中使用,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注创新互联成都网站设计公司行业资讯频道。

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:AngularJS怎么在Node.js中使用-创新互联
转载来源:http://ybzwz.com/article/cedhhj.html

其他资讯