AngularJS学习--- AngularJS中数据双向绑定(two-way data-binding) orderBy step4
2014-05-07 01:16
781 查看
1.切换工作目录
git checkout step-4 #切换分支,切换到第4步 npm start #启动项目
2.代码
app/index.htmlSearch: <input ng-model="query"> Sort by: <select ng-model="orderProp"> <option value="name">Alphabetical</option> <option value="age">Newest</option> </select> <ul class="phones"> <li ng-repeat="phone in phones | filter:query | orderBy:orderProp"> {{phone.name}} <p>{{phone.snippet}}</p> </li> </ul>
app/controllers.js
var phonecatApp = angular.module('phonecatApp', []); phonecatApp.controller('PhoneListCtrl', function($scope) { $scope.phones = [ {'name': 'Nexus S', 'snippet': 'Fast just got faster with Nexus S.', 'age': 1}, {'name': 'Motorola XOOM™ with Wi-Fi', 'snippet': 'The Next, Next Generation tablet.', 'age': 2}, {'name': 'MOTOROLA XOOM™', 'snippet': 'The Next, Next Generation tablet.', 'age': 3} ]; $scope.orderProp = 'age'; });
3.效果
按字母排序:amosli@amosli-pc:~/develop/angular-phonecat/test/e2e$ cat scenarios.js 'use strict'; /* http://docs.angularjs.org/guide/dev_guide.e2e-testing */ describe('PhoneCat App', function() { describe('Phone list view', function() { beforeEach(function() { browser.get('app/index.html'); }); it('should filter the phone list as user types into the search box', function() { var phoneList = element.all(by.repeater('phone in phones')); var query = element(by.model('query')); expect(phoneList.count()).toBe(3); query.sendKeys('nexus'); expect(phoneList.count()).toBe(1); query.clear(); query.sendKeys('motorola'); expect(phoneList.count()).toBe(2); }); it('should be possible to control phone order via the drop down select box', function() { var phoneNameColumn = element.all(by.repeater('phone in phones').column('{{phone.name}}')); var query = element(by.model('query')); function getNames() { return phoneNameColumn.map(function(elm) { return elm.getText(); }); } query.sendKeys('tablet'); //let's narrow the dataset to make the test assertions shorter expect(getNames()).toEqual([ "Motorola XOOM\u2122 with Wi-Fi", "MOTOROLA XOOM\u2122" ]); element(by.model('orderProp')).findElement(by.css('option[value="name"]')).click(); expect(getNames()).toEqual([ "MOTOROLA XOOM\u2122", "Motorola XOOM\u2122 with Wi-Fi" ]); }); }); });
View Code
相关文章推荐
- AngularJS中数据双向绑定(two-way data-binding)
- 双向数据绑定---AngularJS的基本原理学习
- 深入学习AngularJS中数据的双向绑定机制
- 深入学习AngularJS中数据的双向绑定机制
- angularjs中$http、$location、$watch及双向数据绑定学习实现简单登陆验证
- 双向数据绑定---AngularJS的基本原理学习
- 双向数据绑定---AngularJS的基本原理学习
- AngularJs学习记录--双向数据绑定的HelloWorld!
- Angularjs 学习笔记-2017-02-06-双向数据绑定
- Android中的数据绑定框架DataBinding(对比AngularJS双向数据绑定很好理解)
- angularjs学习笔记之双向数据绑定
- angularjs中$http、$location、$watch及双向数据绑定学习实现简单登陆验证
- 双向数据绑定---AngularJS的基本原理学习
- 我的angularjs源码学习之旅3——脏检测与数据双向绑定
- angularjs学习笔记之双向数据绑定
- JS学习笔记——AngularJS 1.x双向数据绑定机制
- AngularJS双向数据绑定的源码分析
- AngularJS数据双向绑定
- AngularJS的数据双向绑定是怎么实现的?