AngularJS 1.5.0-beta.2

With AngularJS 1.5.0-beta.2, we’ve improved the performance and flexibility of Angular 1 while still maintaining reliability and functionality for existing applications. This version contains numerous weeks worth of fixes, documentation upgrades and performance improvements. 1.5.0-beta.2 also introduces a number of new features which should give a strong motivation for you to upgrade. The new features are as follows:

module.component

We have created a more simplistic way of registering component directives. In essence, components are special kinds of  directives, which are bound to a custom element (something like “<my-widget></my-widget>”), with an associated template and some bindings. Now, by using the .component() method in AngularJS 1.5, you can create a reusable component with very few lines of code:

var myApp = angular.module("MyApplication", [])
myApp.component("my-widget", {
 templateUrl: "my-widget.html",
 controller: "MyWidgetController",
 bindings: {
   title: "="
 }
});

To learn more about the AngularJS 1.5 component method please read Todd Motto's article:
http://toddmotto.com/exploring-the-angular-1-5-component-method/

ng-animate-swap

Another feature that may interest you is the new directive called ng-animate-swap. This new directive’s purpose is to animate a collection of DOM changes together as a container swap. By using the ng-animate-swap directive, you can trigger Angular to animate an “old” block away and animate in a “new” block via leave and enter animations respectively.

Let’s imagine that we have a banner image on a webpage that is tied to an expression like so:

<div class="banner-container">
 <img ng-src="{{ currentBannerImage }}" />
</div>

Now if we change currentBannerImage value to another banner, the image will be updated to reflect the new banner image. But if we wanted to animate the old banner away and then animate the new one in we would would have to do something complicated like set up a repeated list of banners and cycle through.

By using ng-animate-swap we can do this without having to change our template code around:

<div class="banner-container">
 <img ng-src="{{ currentBannerImage }}"
      class=”animate-banner”
      ng-animate-swap="currentBannerImage" />
</div>

Now whenever the currentBannerImage expression changes there will be a leave and an enter animation, which we can hook into via CSS or JS animations using ngAnimate.

.animate-banner.ng-enter, .animate-banner.ng-leave {
 position:absolute;
 top:0;
 left:0;
 right:0;
 height:100%;
 transition:0.5s ease-out all;
}
.animate-banner.ng-enter {
 top:-100%;
}
.animate-banner.ng-enter-active, .animate-banner.ng-leave {
 top:0;
}
.animate-banner.ng-leave-active {
 top:100%;
}
What's great about ng-animate-swap is that we can apply it to any container for which we want to render a visual animation, whenever its associated data changes. In the example below, the user-container div is animated whenever the userId on the scope changes.
<div class="user-container" ng-animate-swap="userId">
 <h2>{{ title }}</h2>
 <p>{{ description }}</p>
 <ol>
 <li ng-repeat="attribute in attributes">
   {{ attribute }}
 </li>
 </ol>
</div>

Multi-slot transclusion

The third feature that we’re showcasing is multi-slot transclusion. This allows for pieces of the transcluded HTML to be placed into different parts of a directive’s template. Regular transclusion is useful to project outer content into the template of a component, but with multi-slot transclusion we can take this a step further. Consider a component called <autocomplete-widget>, which collects data from the user and displays the results, where the application developer is allowed to provide the HTML for the input and the results.

<autocomplete-widget>
<!-- inputArea -->
<input type="text"
      ng-model="app.search"
      placeholder="Search..." />
 
<!-- resultsArea -->
<results>
 <div ng-repeat="item in app.getResults(app.search) as results">
   {{ item }}
 </div>
 <div ng-if="results.length==0">
   No results found
 </div>
</results>
</autocomplete-widget>
Now what we want to do here is to transclude the inputArea and resultsArea at specific places in the component's template. Prior to named transclusion, the transclusion would be projected at only one place in the template of the autocomplete-widget. However, with multi-slot transclusion, we can do something like this:

<!-- autocomplete-widget-tpl.html -->
<div class="autocomplete-container">
 <div class="search-area">
   <div class="search-icon">
     <i class="fa fa-search"></i>
   </div>
   <div class="search-input" ng-transclude="inputArea"></div>
 </div>
 <div class="results-area">
   <div ng-transclude="resultsArea"></div>
 </div>
</div>
And here is what the component code for that looks like:

.component('autocompleteWidget', {
 templateUrl: 'autocomplete-widget-tpl.html',
 transclude: {
   input: 'inputArea',
   results: 'resultsArea'
 }
});
To learn more about multi-slot transclusion please read this article by Pascal Precht:

AngularJS 1.5.0-beta.2 and 1.4.8 have been released的更多相关文章

  1. Mozilla Firefox 24.0 Beta 5 发布

    Mozilla今天将Firefox 24.0 Beta 5版本放到了FTP的release目录,新版开始全面支持OS X 10.7全新的滚动条样式,禁止网站插件运行的功能出现在任务栏左侧,调整了界面U ...

  2. 使用cocos2d-x 3.0 beta开发的小游戏

    主要是参考了http://philon.cn/post/cocos2d-x-3.0-zhi-zuo-heng-ban-ge-dou-you-xi 这篇文章,只是移植到了3.0 beta版. 代码地址: ...

  3. 千寻浏览器 1.0 Beta 1(524)(2014年5月27日)

    千寻浏览器--又一款新生浏览器今天进入各位浏览迷的视野.千寻浏览器基于IE内核,据传是由百度浏览器的上海团队操刀,在功能定位上,与目前的QQ浏览器有些相似. 千寻来自官方的解释:寻,追寻,探索,又是古 ...

  4. ENVI 5.0 Beta 体验——影像数据的显示

    ENVI 5.0 Beta采用了全新的软件界面,数据的显示和操作跟以往的三视窗方式有很大的区别,下面一块体验一下. 对于栅格数据的显示方面,5.0有了非常大的改进,采用的全新的金字塔计算方法,在第一次 ...

  5. PyRedisAdmin v1.0 Beta 发布,Redis 在线管理工具 - 开源中国社区

    PyRedisAdmin v1.0 Beta 发布,Redis 在线管理工具 - 开源中国社区 PyRedisAdmin v1.0 Beta 发布,Redis 在线管理工具

  6. 【AngularJS】 2.0 版本发布

    [AngularJS] 2.0 版本发布 w5cValidator[AngularJS] 2.0 版本发布   w5cValidator 插件基于angular原有的表单验证,在原有的基础上扩展了一些 ...

  7. [译]AngularJS 1.3.0 开发者指南(一) -- 介绍

    [译]AngularJS 1.3.0 开发者指南(一) -- 介绍 Angular是什么 ? AngularJS是一款针对动态web应用的结构框架. 它可以让像使用模板语言使用HTML, 并且可以扩展 ...

  8. 在Ubuntu中部署并测试Fabric 1.0 Beta

    [更新:1.0Beta已经是过去式了,现在出了1.0.0的正式版,请大家参照 http://www.cnblogs.com/studyzy/p/7437157.html  安装Fabric 1.0.0 ...

  9. 【开源】EasyFlash 新年发布 V4.0 beta 版,完全重写(转)

    [开源]EasyFlash 新年发布 V4.0 beta 版,完全重写 EasyFlash V4.0 beta [开源]嵌入式闪存库 EasyFlash for STM32,支持Env和IAP

  10. gNewSense 3.0 Beta 2 发布

    gNewSense 3.0 Beta 2 发布,下载地址:gnewsense-livecd-parkes-i386-3.0beta2.iso (1,078MB, MD5, torrent). 发行通知 ...

随机推荐

  1. python3爬虫再探之EXCEL(续)

    上篇介绍了xlsxwriter的用法,本来想写一下xlrd和xlwt的用法,看到这篇文章——http://blog.csdn.net/wangkai_123456/article/details/50 ...

  2. 20145210 《Java程序设计》第一周学习总结

    教材学习内容总结 第一章: 1.Java三大平台,JavaSE的四个组成部分 Java根据应用领域的不同,区分为Java SE.Java EE.Java ME三大平台. 各应用平台的基础:Java S ...

  3. Selenium - 实现网页元素拖拽

    Drag and Drop, 使用鼠标实现元素拖拽的操作貌似很复杂, 在Selenium中, 借助OpenQA.Selenium.Interactions.Actions类库中提供的方法, 实现起来还 ...

  4. C/C++学习之路

    在嵌入式的路上,仅仅会一种C语言是远远不够的,所以便在学习stm32的同时,开始学习C++,为以后做准备.由于学习之初,为了能激发自己的兴趣,便模仿别人写了一个截屏小软件,当然可能是世上最垃圾的截图软 ...

  5. magento中的ajax

    <script type="text/javascript">        function loadRecommend(){         $.ajax({    ...

  6. 实例讲解Oracle数据库设置默认表空间问题

    实例讲解Oracle数据库设置默认表空间问题   实例讲解Oracle数据库设置默认表空间问题,阅读实例讲解Oracle数据库设置默认表空间问题,DBA们经常会遇到一个这样令人头疼的问题:不知道谁在O ...

  7. JavaScript数据结构——集合、字典和散列表

    集合.字典和散列表都可以存储不重复的值. 在集合中,我们感兴趣的是每个值本身,并把它当作主要元素.在字典和散列表中,我们用 [键,值] 的形式来存储数据. 集合(Set 类):[值,值]对,是一组由无 ...

  8. Android内存管理机制之一:low memory killer

    转载自http://www.miui.com/thread-29268-1-1.html 准备写这个专题之前,心里是有点忐忑的.首先Android内存管理机制相当复杂,想要讲清楚比较困难:其次对于绝大 ...

  9. sql server触发器中增删改判断

    触发器生效逻辑 在Before或者After之后使用INSERT,DELETE,UPDATE 触发器内情况判断 插入 if exists(select 1 from inserted) and not ...

  10. Linux档案与目录的管理

    本篇随笔中,主要介绍在Linux环境下,与档案和目录的管理相关的一些命令使用,具体包括如下几个方面: 目录的相关操作:cd,pwd,mkdir,rmdir(rm) 档案与目录的查视:ls 复制.删除与 ...