Pro AngularJS
深入介绍如何使用AngularJS开发前端应用,并和BootStrap同时使用,捎带介绍了如何用AngularJS开发移动应用。是学习AngularJS框架不可多得的资料。Contents at a glanceAbout the authorAbout the technical reviewerPart 1: Getting ready aChapter 1: Getting Ready mamm maman. 3Chapter 2: Your First AngularJS App amana. 15Chapter 3: Putting AngularJs in Context45Chapter 4: HTML and bootstrap cSs Primerman■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■55Chapter 5: JavaScript Primer■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■口75Chapter6: Sportsstore: A Real Application,…,…,…,…,…,,,119Chapter 7: SportsStore: Navigation and checkout■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■149Chapter8: Sports Store: Orders and administration,,,,…,,,,,,,…,…,…,173Part 2: Working with AngularJS205Chapter 9: The Anatomy of an AngularJS App■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■207Chapter10: Using Binding and Template Directives,,,,,,…,…,,,,…,…233Chapter 11: Using Element and Event Directives263Chapter 12: Working with Forms285Chapter 13: Using Controllers and Scopes■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■319Chapter14: Using Filters…,,,…,,,,,,,,…,,,,,,,351Chapter 15: Creating Custom Directives.381CONTENTS AT A GLANCIChapter 16: creating Complex Directives mm mman413Chapter 17: Advanced Directive Features BR RBRRRHRRRIRIIIIIIIIII 447Part 3: AngularJs Services mammmaammammmmmmmma. 471Chapter 18: Working with Modules and Services.473Chapter 19: Services for Global Objects, Errors and Expressions mmImaImIm 489Chapter 20: Services for Ajax and promises■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■■■■■■■■■■■■■■■■■■■■■■■523Chapter 21: Services for RESTa■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■551Chapter 22: Services for Views579Chapter 23: Services for Animation and Touch m.603■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■Chapter 24: Services for Provision and Injection mm mmamaammnnm 613Chapter 25: Unit Testing mmm a II a Ia IIIIIIIERIn 623Index u 651PART 1Getting ReadyCHAPTER 1Getting ReadyAngularjS taps into some of the best aspects of server-side development and uses them to enhance html in thebrowser, creating a foundation that makes building rich applications simpler and easier. AngularJS applicationsare built around a design pattern called Model-View-Controller (MVC), which places an emphasis on creatingapplications that areExtendable: It is easy to figure out how even a complex angular]S app works once youunderstand the basics-and that means you can easily enhance applications to create newand useful features for your usersMaintainable: angular]S apps are easy to debug and fix, which means that long-termmaintenance is simplifiedTestable: Angular]s has good support for unit and end-to-end testing, meaning that you canfind and fix defects before your users doStandardized: Angular]s builds on the innate capabilities of the web browser without gettingin your way, allowing you to create standards-compliant web apps that take advantage of thelatest features(such as HTML5 APIs)and popular tools and frameworksAngular s is an open source java Script library that is sponsored and maintained by google. it has been used insome of the largest and most complex web apps around. In this book, I show you everything you need to know to getthe benefits of Angular]S in your own projectsWhat do you need to know?Before reading this book, you should be familiar with the basics of web development, have an understanding of howHTML and CSs work, and, ideally, have a working knowledge of JavaScript. If you are a little hazy on some of thesedetails, I provide refreshers for the HTML, CSS, and Java Script I use in this book in Chapters 4 and 5. You wont findcomprehensive reference for htMl elements and css properties though There just isn 't the space in a book aboutAngularJS to cover HTML in its entirety. If you want a complete reference for HTML and CSS, then I suggest another ofmy books, The Definitive Guide to HTML5, also published by ApressWhat is the structure of this book?This book is split into three parts, each of which covers a set of related topicsCHAPTER 1 GETTING READYPart 1: Getting ReadyPart 1 of this book provides the information you need to get ready for the rest of the book. It includes this chapter andprimers/refreshers for HTML, CSS, and JavaScript. I also show you how to build your first angular JS application andtake you through the process of building a more realistic application, called Sports StorePart 2: Working with AngularIsPart 2 of this book takes you through the features of the AngularJS library, starting with an overview of the differenttypes of components in an Angular]S application and then working through each type in turn. AngularjS includesa lot of built-in functionality, which I describe in depth, and provides endless customization options, all of whichi demonstratePart 3: Angular)S Modules and servicesPart 3 of this book explains the roles that two important components play in AngularJS: modules and services. I showyou the different ways you can create both components and explain the wide range of built-in services that AngularJSprovides. This includes support for simplifying Single-Page Application development, Ajax and RESTful APIs, andunit testing.Are There Lots of Examples?There are loads of examples. The best way to learn AngulariS is by example, and i have packed as many of them asI can into this book. To maximize the number of examples in this book, I have adopted a simple convention to avoidlisting the contents of files over and over again. The first time I use a file in a chapter, I'll list the complete contentsjust as I have in Listing 1-1.Listing 1-1. A Complete Example Documentto do ListCHAPTER 1 GETTING READY elements omitted for brevity.