AngularJS - Novice to Ninja.pdf.pdf )
非常不错的书
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Who Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Conventions Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
Code Samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
Tips, Notes, and Warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Supplementary Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Want to Take Your Learning Further? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Chapter 1 Falling In Love With AngularJS . . . . . 1
The Power Features of AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Download and Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Installing via CDN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Hosting on Your Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Required Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
AngularJS Batarang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Angular Seed Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
The Anatomy of an AngularJS app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
What is MVW? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Structuring Our Code With MVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Unit and End-to-End Testing in AngularJS . . . . . . . . . . . . . . . . . . . . . . . . 17
Where to Put Your Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
How to Run Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
When Not To Use AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Chapter 2 Modules, Controllers & Data
Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Creating Our First Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Modular Programming Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
The Role of a Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Attaching Properties and Functions to Scope . . . . . . . . . . . . . . . . . . 30
Adding Logic to the Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Adding Instance Functions and Properties to Controllers . . . . . . . . 35
Dependency Injection in Controllers With Minification . . . . . . . . . 37
Overview of Two-Way Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
What Is Data Binding? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Two-Way Binding in AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Doing Something Cool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Introducing Our Demo Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The Single Page Blogger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Getting Ready . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Chapter 3 AngularJS Scope & Events . . . . . . . . . . . . 45
Scope Demystified . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Writing Access with Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Objects Can Extend Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Prototypal Inheritance in AngularJS Scopes . . . . . . . . . . . . . . . . . . . . . . . 49
Advanced Scope Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
The Watchers in AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
The $watchCollection() Function . . . . . . . . . . . . . . . . . . . . . . . 56
The $apply() Function and the $digest Loop . . . . . . . . . . . . . . 57
$apply and $digest in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
x
Broadcasting & Emitting Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
$scope.$emit(name,args) For Emitting Events . . . . . . . . . . . . 64
$scope.$broadcast(name,args) For Broadcasting
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
$scope.$on(name,handlerFunction) For Registering
Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Events in Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
The $destroy event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Chapter 4 Multiple Views and Routing . . . . . . . . . 71
Creating Multiple Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Using $routeParams in the Controller . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Using ng-template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The resolve Property in the Route Config Object . . . . . . . . . . . . . . . . . 83
Exploring the $location Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
The API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Events in Routing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
$location related events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
$route related events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
The ng-include Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Introducing the Angular UI Router . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Getting Started With UI Routter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Defining States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Chapter 5 AngularJS Services, Factories, and
Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
xi
Eager Loading of a Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Factory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Using Decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Chapter 6 Developing Single Page Blogger . . . 113
Developing Our App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Defining Routes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Creating Our Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Creating the Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Creating the Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
App Entry Point (index.html) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
How About Some Unit Tests? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Unit Testing postService . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Unit Testing Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Writing an End-to-End (e2e) Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Chapter 7 Understanding AngularJS
Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
AngularJS Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
<input> and <textarea> controls . . . . . . . . . . . . . . . . . . . . . . . 130
<select> control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Radio Button Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Checkbox Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
AngularJS Form Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
xii
Applying Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Updating Models With a Twist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Forms in Action : Single Page Blogger v1.1 . . . . . . . . . . . . . . . . . . . . . . . 143
Creating the admin Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Defining States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Creating Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Admin Panel Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Template For Adding a New Post . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Chapter 8 Interacting with REST APIs . . . . . . . . . 151
A Primer on Promises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
The Promise API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Example Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Promise Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Creating a Promise that Always Rejects . . . . . . . . . . . . . . . . . . . . . 159
Understanding the $http Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
The config Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
A Weather Search Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Setting Request Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Request and Response Transformers . . . . . . . . . . . . . . . . . . . . . . . . 166
Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Interceptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Understanding AngularJS $resource . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
How Does $resource Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
xiii
Chapter 9 Using REST APIs in Single Page
Blogger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Applying $resource to Our App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Defining Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Defining Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Including angular-resource.js and Adding the ngResource
Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Unit Testing Our Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Chapter 10 AngularJS Directives . . . . . . . . . . . . . . . . . . 193
What Are Directives, Really? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Directives From the jQuery Perspective . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Creating Custom Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
The Link Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
The Compile Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Compilation of Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Changing a Directive’s Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Binding Between Parent Scope and Isolated Scope Models . . . . . . . . . 207
Using @ For One-Way Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Using = For Two-Way Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Using & to Execute Functions in the Parent Scope . . . . . . . . . . . . 209
Parent Scope vs. Child Scope vs. Isolated Scope . . . . . . . . . . . . . . . . . . . 212
Transclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Differences Between transclude:'element' and
transclude:true . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
The Controller Function and Require . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Cleaning Up Your Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
IE 8 Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
xiv
Chapter 11 Adding a Comment System to
Single Page Blogger . . . . . . . . . . . . . . . . . . . . 219
Unit Testing Our Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Chapter 12 Dependency Injection In
AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
A Brief Recap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
The $provide Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
The $injector Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Dynamically Injecting a Dependency . . . . . . . . . . . . . . . . . . . . . . . . 230
Registration of Controllers, Filters, and Directives . . . . . . . . . . . . . 230
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Chapter 13 AngularJS Filters . . . . . . . . . . . . . . . . . . . . . . . 233
Filter Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Fun with Custom Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Chaining Multiple Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Using Filters in Controllers, Services, and Directives . . . . . . . . . . . 236
Meet a Filter Called filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
Meet the orderBy Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Meet the limitTo Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Using the $filter Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Using Filters in Single Page Blogger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Permalink Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Wordcount Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
xv
Chapter 14 AngularJS Animation . . . . . . . . . . . . . . . . . 245
Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Animation with CSS3 Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Going Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Animation Using Keyframes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Animation Using jQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Animation Using ngClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Animation with Custom Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Adding Simple Animation to Single Page Blogger . . . . . . . . . . . . . . . . . 257
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Chapter 15 Deployment and
Internationalization . . . . . . . . . . . . . . . . . . . 259
Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Chapter 16 Authentication and Authorization
in AngularJS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Adding Login Functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Authorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Where To Go Next? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Things to Do Now . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Improving Our Demo App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Host it Yourself : Back-end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
自己动手写开发工具 源码及部分章节
自己动手写开发工具.rar包括:
《自己动手写开发工具》随书光盘.rar
自己动手写开发工具-部分章节.pdf
图表FusionCharts TagLib JSF源码
FusionChartsTagLibSourceCode.zip
没想到只能上传一个附件,补上源码
图表fusioncharts JSF taglib 和 源码
在JSF中使用fusioncharts,是多么令人兴奋的事!
最近试用fusioncharts,找到了fusioncharts的jsf1.2的jar包,好高兴,分享。
环境:
jsf1.2 + facelts + richfaces + fusioncharts
Richfaces get started
Richfaces start。it's very good.
eclipse 属性页
属性页 properties:table / tabletree/ tab