mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 11:37:38 +08:00
style(docs): make jslint happy - fix some warnings
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
@ngdoc overview
|
||||
@name angular.module.NG
|
||||
@description
|
||||
|
||||
The `NG` is an angular module which contains all of the core angular services.
|
||||
@@ -25,7 +25,7 @@ function MyModule($provide, $locationProvider){
|
||||
};
|
||||
</pre>
|
||||
|
||||
See: {@link angular.module.AUTO.$provide $provide}, {@link angular.module.NG.$locationProvider $locationProvider}.
|
||||
See: {@link angular.module.AUTO.$provide $provide}, {@link angular.module.ng.$locationProvider $locationProvider}.
|
||||
|
||||
# Registering Module Function
|
||||
|
||||
@@ -44,11 +44,11 @@ angular.module.MyModule = function(){
|
||||
Then you can refer to your module like this:
|
||||
|
||||
<pre>
|
||||
var injector = angular.injector('NG', 'MyModule')
|
||||
var injector = angular.injector('ng', 'MyModule')
|
||||
</pre>
|
||||
|
||||
Or
|
||||
|
||||
<pre>
|
||||
var injector = angular.injector('NG', angular.module.MyModule)
|
||||
var injector = angular.injector('ng', angular.module.MyModule)
|
||||
</pre>
|
||||
|
||||
@@ -7,23 +7,23 @@
|
||||
* {@link angular.widget Widgets} - Angular custom DOM element
|
||||
* {@link angular.directive Directives} - Angular DOM element attributes
|
||||
* {@link angular.markup Markup} and {@link angular.attrMarkup Attribute Markup}
|
||||
* {@link angular.module.NG.$filter Filters} - Angular output filters
|
||||
* {@link angular.module.NG.$compile $compile} - Template compiler
|
||||
* {@link angular.module.ng.$filter Filters} - Angular output filters
|
||||
* {@link angular.module.ng.$compile $compile} - Template compiler
|
||||
|
||||
## Angular Scope API
|
||||
|
||||
* {@link angular.module.NG.$rootScope.Scope Scope Object} - Angular scope object
|
||||
* {@link angular.module.ng.$rootScope.Scope Scope Object} - Angular scope object
|
||||
|
||||
|
||||
## Angular Services & Dependency Injection API
|
||||
|
||||
* {@link angular.module.NG Angular Services}
|
||||
* {@link angular.module.ng Angular Services}
|
||||
* {@link angular.injector angular.injector() }
|
||||
|
||||
|
||||
## Angular Testing API
|
||||
|
||||
* {@link angular.module.NG_MOCK Testing Mocks API} - Mock objects for testing
|
||||
* {@link angular.module.ngMock Testing Mocks API} - Mock objects for testing
|
||||
* {@link guide/dev_guide.e2e-testing Angular Scenario Runner} - Automated scenario testing
|
||||
documentation
|
||||
|
||||
|
||||
@@ -105,9 +105,9 @@ The two partials are defined in the following URLs:
|
||||
# Things to notice
|
||||
|
||||
* Routes are defined in the `AppCntl` class. The initialization of the controller causes the
|
||||
initialization of the {@link api/angular.module.NG.$route $route} service with the proper URL
|
||||
initialization of the {@link api/angular.module.ng.$route $route} service with the proper URL
|
||||
routes.
|
||||
* The {@link api/angular.module.NG.$route $route} service then watches the URL and instantiates the
|
||||
* The {@link api/angular.module.ng.$route $route} service then watches the URL and instantiates the
|
||||
appropriate controller when the URL changes.
|
||||
* The {@link api/angular.widget.ng:view ng:view} widget loads the view when the URL changes. It
|
||||
also
|
||||
|
||||
@@ -104,7 +104,7 @@ allow a user to enter data.
|
||||
|
||||
* The user data model is initialized {@link api/angular.directive.ng:controller controller} and is
|
||||
available in
|
||||
the {@link api/angular.module.NG.$rootScope.Scope scope} with the initial data.
|
||||
the {@link api/angular.module.ng.$rootScope.Scope scope} with the initial data.
|
||||
* For debugging purposes we have included a debug view of the model to better understand what
|
||||
is going on.
|
||||
* The {@link api/angular.widget.input input widgets} simply refer to the model and are data-bound.
|
||||
|
||||
@@ -31,7 +31,7 @@ Take a look through the source and note:
|
||||
* The script tag that {@link guide/dev_guide.bootstrap bootstraps} the angular environment.
|
||||
* The text {@link api/angular.widget.input input widget} which is bound to the greeting name text.
|
||||
* No need for listener registration and event firing on change events.
|
||||
* The implicit presence of the `name` variable which is in the root {@link api/angular.module.NG.$rootScope.Scope scope}.
|
||||
* The implicit presence of the `name` variable which is in the root {@link api/angular.module.ng.$rootScope.Scope scope}.
|
||||
* The double curly brace `{{markup}}`, which binds the name variable to the greeting text.
|
||||
* The concept of {@link guide/dev_guide.templates.databinding data binding}, which reflects any
|
||||
changes to the
|
||||
|
||||
@@ -44,7 +44,7 @@ allowing you to send links to specific screens in your app.
|
||||
|
||||
# Services
|
||||
|
||||
{@link api/angular.module.NG Services}: Services are long lived objects in your applications that are
|
||||
{@link api/angular.module.ng Services}: Services are long lived objects in your applications that are
|
||||
available across controllers. A collection of useful services are pre-bundled with angular but you
|
||||
will likely add your own. Services are initialized using dependency injection, which resolves the
|
||||
order of initialization. This safeguards you from the perils of global state (a common way to
|
||||
|
||||
@@ -121,4 +121,4 @@ board variable.
|
||||
* The view can call any controller function.
|
||||
* In this example, the `setUrl()` and `readUrl()` functions copy the game state to/from the URL's
|
||||
hash so the browser's back button will undo game steps. See deep-linking. This example calls {@link
|
||||
api/angular.module.NG.$rootScope.Scope#$watch $watch()} to set up a listener that invokes `readUrl()` when needed.
|
||||
api/angular.module.ng.$rootScope.Scope#$watch $watch()} to set up a listener that invokes `readUrl()` when needed.
|
||||
|
||||
@@ -98,4 +98,4 @@ APIs are bound to fields of this global object.
|
||||
|
||||
## Related API
|
||||
|
||||
{@link api/angular.module.NG.$compile Compiler API}
|
||||
{@link api/angular.module.ng.$compile Compiler API}
|
||||
|
||||
@@ -43,4 +43,4 @@ an executable, bi-directionally bound application.
|
||||
|
||||
## Related API
|
||||
|
||||
{@link api/angular.module.NG.$compile Compiler API}
|
||||
{@link api/angular.module.ng.$compile Compiler API}
|
||||
|
||||
@@ -23,7 +23,7 @@ angular.directive('ng:bind', function(expression, compiledElement) {
|
||||
The angular compiler exposes methods that you may need to use when writing your own widgets and
|
||||
directives. For example, the `descend()` method lets you control whether the compiler ignores or
|
||||
processes child elements of the element it is compiling. For information on this and other
|
||||
compiler methods, see the {@link api/angular.module.NG.$compile Compiler API doc}.
|
||||
compiler methods, see the {@link api/angular.module.ng.$compile Compiler API doc}.
|
||||
|
||||
|
||||
## Related Docs
|
||||
|
||||
@@ -93,4 +93,4 @@ corresponding spans.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile $compile()}
|
||||
* {@link api/angular.module.ng.$compile $compile()}
|
||||
|
||||
@@ -89,4 +89,4 @@ angular.attrMarkup('extraClass', function(attrValue, attrName, element){
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile Compiler API Reference}
|
||||
* {@link api/angular.module.ng.$compile Compiler API Reference}
|
||||
|
||||
@@ -23,4 +23,4 @@ All compilation takes place in the web browser; no server is involved.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile Angular Compiler API}
|
||||
* {@link api/angular.module.ng.$compile Angular Compiler API}
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile $compile()}
|
||||
* {@link api/angular.module.ng.$compile $compile()}
|
||||
|
||||
@@ -20,7 +20,7 @@ dataset]"`), the link function gets called to set up a listener on each element
|
||||
|
||||
Note that angular's built-in widgets, directives, and markup have predefined compile and link
|
||||
functions that you don't need to modify. When you create your own widgets, directives, or markup,
|
||||
you must write compile and link functions for them. Refer to the {@link api/angular.module.NG.$compile
|
||||
you must write compile and link functions for them. Refer to the {@link api/angular.module.ng.$compile
|
||||
Compiler API} for details.
|
||||
|
||||
When the angular compiler compiles a page, it proceeds through 3 phases: Compile, Create Root
|
||||
@@ -53,7 +53,7 @@ Note that while the compile function is executed exactly once, the link function
|
||||
multiple times, for example, once for each iteration in a repeater.
|
||||
|
||||
The angular compiler exposes methods that you will need to make use of when writing your own
|
||||
widgets and directives. For information on these methods, see the {@link api/angular.module.NG.$compile
|
||||
widgets and directives. For information on these methods, see the {@link api/angular.module.ng.$compile
|
||||
Compiler API doc}.
|
||||
|
||||
|
||||
@@ -65,4 +65,4 @@ Compiler API doc}.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile $compile()}
|
||||
* {@link api/angular.module.ng.$compile $compile()}
|
||||
|
||||
@@ -80,7 +80,7 @@ angular.widget('my:time', function(compileElement){
|
||||
The angular compiler exposes methods that you may need to use of when writing your own widgets and
|
||||
directives. For example, the `descend()` method lets you control whether the compiler ignores or
|
||||
processes child elements of the element it is compiling. For information on this and other
|
||||
compiler methods, see the {@link api/angular.module.NG.$compile Compiler API doc}.
|
||||
compiler methods, see the {@link api/angular.module.ng.$compile Compiler API doc}.
|
||||
|
||||
|
||||
## Related Topics
|
||||
@@ -92,4 +92,4 @@ compiler methods, see the {@link api/angular.module.NG.$compile Compiler API doc
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile Compiler API}
|
||||
* {@link api/angular.module.ng.$compile Compiler API}
|
||||
|
||||
@@ -32,4 +32,4 @@ dev_guide.compiler.widgets.creating_widgets Creating Custom Widgets}.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile Compiler API}
|
||||
* {@link api/angular.module.ng.$compile Compiler API}
|
||||
|
||||
@@ -28,5 +28,5 @@ book.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Service API}
|
||||
* {@link api/angular.module.ng Service API}
|
||||
* {@link api/angular.injector Angular Injector API}
|
||||
|
||||
@@ -7,15 +7,15 @@ While DI is widely used in statically typed languages such as Java or C++, it ha
|
||||
used in JavaScript. Angular brings the benefits of DI into JavaScript apps.
|
||||
|
||||
In angular, DI is implemented as a subsystem that manages dependencies between services,
|
||||
controllers, widgets, and filters. The most important of these are {@link api/angular.module.NG
|
||||
controllers, widgets, and filters. The most important of these are {@link api/angular.module.ng
|
||||
services}.
|
||||
|
||||
Services are objects that handle common tasks in web applications. Angular provides several{@link
|
||||
api/angular.module.NG built-in services}, and you can create your own custom services.
|
||||
api/angular.module.ng built-in services}, and you can create your own custom services.
|
||||
|
||||
The main job of angular's DI subsystem is to provide services to angular components that depend on
|
||||
them. The way the DI subsystem provides services is as follows: all services are registered with
|
||||
angular's {@link api/angular.module.NG service API}, and all components that depend on services
|
||||
angular's {@link api/angular.module.ng service API}, and all components that depend on services
|
||||
define those dependencies as a property (`$inject`). With this information, the DI subsystem
|
||||
manages the creation of service objects and the provision of those objects to the components that
|
||||
need them, at the time they need them. The following illustration steps through the sequence of
|
||||
@@ -49,7 +49,7 @@ achieve the necessary isolation by having each test create its own separate root
|
||||
|
||||
<pre>
|
||||
// create a root scope
|
||||
var rootScope = angular.module.NG.$rootScope.Scope();
|
||||
var rootScope = angular.module.ng.$rootScope.Scope();
|
||||
// access the service locator
|
||||
var myService = rootScope.$service('myService');
|
||||
</pre>
|
||||
@@ -74,7 +74,7 @@ equivalent:
|
||||
|
||||
<pre>
|
||||
// given a user defined service
|
||||
angular.module.NG('serviceA', ...);
|
||||
angular.module.ng('serviceA', ...);
|
||||
|
||||
// inject '$window', 'serviceA', curry 'name';
|
||||
function fnA($window, serviceA, name){};
|
||||
@@ -102,4 +102,4 @@ code and insert the `$inject` into the source code so that it can be minified/ob
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Services API}
|
||||
* {@link api/angular.module.ng Services API}
|
||||
|
||||
@@ -14,7 +14,7 @@ MyController.$inject = ['$route'];
|
||||
</pre>
|
||||
|
||||
In this example, the `MyController` constructor function takes one argument, the {@link
|
||||
api/angular.module.NG.$route $route} service. Angular is then responsible for supplying the instance
|
||||
api/angular.module.ng.$route $route} service. Angular is then responsible for supplying the instance
|
||||
of `$route` to the controller when the constructor is instantiated. There are two ways to cause
|
||||
controller instantiation – by configuring routes with the `$route` service, or by referencing the
|
||||
controller from the HTML template, as follows:
|
||||
|
||||
@@ -78,19 +78,19 @@ Returns the window.location.search of the currently loaded page in the test fram
|
||||
Returns the window.location.hash (without `#`) of the currently loaded page in the test frame.
|
||||
|
||||
## browser().location().url()
|
||||
Returns the {@link api/angular.module.NG.$location $location.url()} of the currently loaded page in
|
||||
Returns the {@link api/angular.module.ng.$location $location.url()} of the currently loaded page in
|
||||
the test frame.
|
||||
|
||||
## browser().location().path()
|
||||
Returns the {@link api/angular.module.NG.$location $location.path()} of the currently loaded page in
|
||||
Returns the {@link api/angular.module.ng.$location $location.path()} of the currently loaded page in
|
||||
the test frame.
|
||||
|
||||
## browser().location().search()
|
||||
Returns the {@link api/angular.module.NG.$location $location.search()} of the currently loaded page
|
||||
Returns the {@link api/angular.module.ng.$location $location.search()} of the currently loaded page
|
||||
in the test frame.
|
||||
|
||||
## browser().location().hash()
|
||||
Returns the {@link api/angular.module.NG.$location $location.hash()} of the currently loaded page in
|
||||
Returns the {@link api/angular.module.ng.$location $location.hash()} of the currently loaded page in
|
||||
the test frame.
|
||||
|
||||
## expect(future).{matcher}
|
||||
|
||||
@@ -165,15 +165,15 @@ JavaScript method instead.
|
||||
Built-in types have methods like `[].push()`, but the richness of these methods is limited.
|
||||
Consider the example below, which allows you to do a simple search over a canned set of contacts.
|
||||
The example would be much more complicated if we did not have the `Array:$filter()`. There is no
|
||||
built-in method on `Array` called {@link api/angular.module.NG.$filter.filter $filter} and angular doesn't add
|
||||
built-in method on `Array` called {@link api/angular.module.ng.$filter.filter $filter} and angular doesn't add
|
||||
it to `Array.prototype` because that could collide with other JavaScript frameworks.
|
||||
|
||||
For this reason the scope expression evaluator augments the built-in types to make them act like
|
||||
they have extra methods. The actual method for `$filter()` is `angular.module.NG.$filter.filter()`. You can
|
||||
they have extra methods. The actual method for `$filter()` is `angular.module.ng.$filter.filter()`. You can
|
||||
call it from JavaScript.
|
||||
|
||||
Extensions: You can further extend the expression vocabulary by adding new methods to
|
||||
`angular.module.NG.$filter` or `angular.String`, etc.
|
||||
`angular.module.ng.$filter` or `angular.String`, etc.
|
||||
|
||||
<doc:example>
|
||||
<doc:source>
|
||||
@@ -212,7 +212,7 @@ of filters like this:
|
||||
|
||||
name | uppercase
|
||||
|
||||
The expression evaluator simply passes the value of name to angular.module.NG.$filter.uppercase.
|
||||
The expression evaluator simply passes the value of name to angular.module.ng.$filter.uppercase.
|
||||
|
||||
Chain filters using this syntax:
|
||||
|
||||
@@ -243,4 +243,4 @@ so that angular developers and developers who use angular can develop in harmony
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$compile Angular Compiler API}
|
||||
* {@link api/angular.module.ng.$compile Angular Compiler API}
|
||||
|
||||
@@ -18,14 +18,14 @@ Forms consist of all of the following:
|
||||
|
||||
A form groups a set of widgets together into a single logical data-set. A form is created using
|
||||
the {@link api/angular.widget.form <form>} element that calls the
|
||||
{@link api/angular.module.NG.$formFactory $formFactory} service. The form is responsible for managing
|
||||
{@link api/angular.module.ng.$formFactory $formFactory} service. The form is responsible for managing
|
||||
the widgets and for tracking validation information.
|
||||
|
||||
A form is:
|
||||
|
||||
- The collection which contains widgets or other forms.
|
||||
- Responsible for marshaling data from the model into a widget. This is
|
||||
triggered by {@link api/angular.module.NG.$rootScope.Scope#$watch $watch} of the model expression.
|
||||
triggered by {@link api/angular.module.ng.$rootScope.Scope#$watch $watch} of the model expression.
|
||||
- Responsible for marshaling data from the widget into the model. This is
|
||||
triggered by the widget emitting the `$viewChange` event.
|
||||
- Responsible for updating the validation state of the widget, when the widget emits
|
||||
@@ -57,7 +57,7 @@ In Angular, a widget is the term used for the UI with which the user input. Exam
|
||||
bult-in Angular widgets are {@link api/angular.widget.input input} and
|
||||
{@link api/angular.widget.select select}. Widgets provide the rendering and the user
|
||||
interaction logic. Widgets should be declared inside a form, if no form is provided an implicit
|
||||
form {@link api/angular.module.NG.$formFactory $formFactory.rootForm} form is used.
|
||||
form {@link api/angular.module.ng.$formFactory $formFactory.rootForm} form is used.
|
||||
|
||||
Widgets are implemented as Angular controllers. A widget controller:
|
||||
|
||||
@@ -218,7 +218,7 @@ The following example demonstrates:
|
||||
# Life-cycle
|
||||
|
||||
- The `<form>` element triggers creation of a new form {@link dev_guide.scopes scope} using the
|
||||
{@link api/angular.module.NG.$formFactory $formfactory}. The new form scope is added to the
|
||||
{@link api/angular.module.ng.$formFactory $formfactory}. The new form scope is added to the
|
||||
`<form>` element using the jQuery `.data()` method for later retrieval under the key `$form`.
|
||||
The form also sets up these listeners:
|
||||
|
||||
@@ -227,8 +227,8 @@ The following example demonstrates:
|
||||
- `$valid` / `$invalid` - This event is emitted by the widget on validation state change.
|
||||
|
||||
- `<input>` element triggers the creation of the widget using the
|
||||
{@link api/angular.module.NG.$formFactory $formfactory.$createWidget()} method. The `$createWidget()`
|
||||
creates new widget instance by calling the current scope {@link api/angular.module.NG.$rootScope.Scope#$new .$new()} and
|
||||
{@link api/angular.module.ng.$formFactory $formfactory.$createWidget()} method. The `$createWidget()`
|
||||
creates new widget instance by calling the current scope {@link api/angular.module.ng.$rootScope.Scope#$new .$new()} and
|
||||
registers these listeners:
|
||||
|
||||
- `$watch` on the model scope.
|
||||
@@ -244,7 +244,7 @@ The following example demonstrates:
|
||||
1. The DOM element fires the `change` event which the widget intercepts. Widget then emits
|
||||
a `$viewChange` event which includes the new user-entered value. (Remember that the DOM events
|
||||
are outside of the Angular environment so the widget must emit its event within the
|
||||
{@link api/angular.module.NG.$rootScope.Scope#$apply $apply} method).
|
||||
{@link api/angular.module.ng.$rootScope.Scope#$apply $apply} method).
|
||||
2. The form's `$viewChange` listener copies the user-entered value to the widget's `$viewValue`
|
||||
property. Since the `$viewValue` is the raw value as entered by user, it may need to be
|
||||
translated to a different format/type (for example, translating a string to a number).
|
||||
@@ -517,7 +517,7 @@ function LoginController() {
|
||||
|
||||
describe('LoginController', function() {
|
||||
it('should disable login button when form is invalid', function() {
|
||||
var scope = angular.module.NG.$rootScope.Scope();
|
||||
var scope = angular.module.ng.$rootScope.Scope();
|
||||
var loginController = scope.$new(LoginController);
|
||||
|
||||
// In production the 'loginForm' form instance gets set from the view,
|
||||
@@ -570,7 +570,7 @@ function LoginController(){
|
||||
|
||||
describe('LoginController', function() {
|
||||
it('should disable login button when form is invalid', function() {
|
||||
var scope = angular.module.NG.$rootScope.Scope();
|
||||
var scope = angular.module.ng.$rootScope.Scope();
|
||||
var loginController = scope.$new(LoginController);
|
||||
var input = angular.element('<input>');
|
||||
|
||||
|
||||
@@ -17,15 +17,15 @@ abstracted bits.
|
||||
**What level of support for i18n/l10n is currently in Angular?**
|
||||
|
||||
Currently, Angular supports i18n/l10n for {@link
|
||||
http://docs.angularjs.org/#!/api/angular.module.NG.$filter.date datetime}, {@link
|
||||
http://docs.angularjs.org/#!/api/angular.module.NG.$filter.number number} and {@link
|
||||
http://docs.angularjs.org/#!/api/angular.module.NG.$filter.currency currency} filters.
|
||||
http://docs.angularjs.org/#!/api/angular.module.ng.$filter.date datetime}, {@link
|
||||
http://docs.angularjs.org/#!/api/angular.module.ng.$filter.number number} and {@link
|
||||
http://docs.angularjs.org/#!/api/angular.module.ng.$filter.currency currency} filters.
|
||||
|
||||
Additionally, Angular supports localizable pluralization support provided by the {@link
|
||||
api/angular.widget.ng:pluralize ng:pluralize widget}.
|
||||
|
||||
All localizable Angular components depend on locale-specific rule sets managed by the {@link
|
||||
api/angular.module.NG.$locale $locale service}.
|
||||
api/angular.module.ng.$locale $locale service}.
|
||||
|
||||
For readers who want to jump straight into examples, we have a few web pages that showcase how to
|
||||
use Angular filters with various locale rule sets. You can find these examples either on {@link
|
||||
@@ -90,8 +90,8 @@ because an extra script needs to be loaded.
|
||||
|
||||
**Currency symbol "gotcha"**
|
||||
|
||||
Angular's {@link http://docs.angularjs.org/#!/api/angular.module.NG.$filter.currency currency filter} allows
|
||||
you to use the default currency symbol from the {@link api/angular.module.NG.$locale locale service},
|
||||
Angular's {@link http://docs.angularjs.org/#!/api/angular.module.ng.$filter.currency currency filter} allows
|
||||
you to use the default currency symbol from the {@link api/angular.module.ng.$locale locale service},
|
||||
or you can provide the filter with a custom currency symbol. If your app will be used only in one
|
||||
locale, it is fine to rely on the default currency symbol. However, if you anticipate that viewers
|
||||
in other locales might use your app, you should provide your own currency symbol to make sure the
|
||||
@@ -104,7 +104,7 @@ browser will specify the locale as ja, and the balance of '¥1000.00' will be sh
|
||||
will really upset your client.
|
||||
|
||||
In this case, you need to override the default currency symbol by providing the {@link
|
||||
http://docs.angularjs.org/#!/api/angular.module.NG.$filter.currency currency filter} with a currency symbol as
|
||||
http://docs.angularjs.org/#!/api/angular.module.ng.$filter.currency currency filter} with a currency symbol as
|
||||
a parameter when you configure the filter, for example, {{ 1000 | currency:"USD$"}}. This way,
|
||||
Angular will always show a balance of 'USD$1000' and disregard any locale changes.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
In angular, a controller is a JavaScript function(type/class) that is used to augment instances of
|
||||
angular {@link dev_guide.scopes Scope}, excluding the root scope. When you or angular create a new
|
||||
child scope object via the {@link api/angular.module.NG.$rootScope.Scope#$new scope.$new} API , there is an
|
||||
child scope object via the {@link api/angular.module.ng.$rootScope.Scope#$new scope.$new} API , there is an
|
||||
option to pass in a controller as a method argument. This will tell angular to associate the
|
||||
controller with the new scope and to augment its behavior.
|
||||
|
||||
@@ -77,9 +77,9 @@ instances).
|
||||
|
||||
# Associating Controllers with Angular Scope Objects
|
||||
|
||||
You can associate controllers with scope objects explicitly via the {@link api/angular.module.NG.$rootScope.Scope#$new
|
||||
You can associate controllers with scope objects explicitly via the {@link api/angular.module.ng.$rootScope.Scope#$new
|
||||
scope.$new} api or implicitly via the {@link api/angular.directive.ng:controller ng:controller
|
||||
directive} or {@link api/angular.module.NG.$route $route service}.
|
||||
directive} or {@link api/angular.module.ng.$route $route service}.
|
||||
|
||||
|
||||
## Controller Constructor and Methods Example
|
||||
@@ -160,7 +160,7 @@ input box) in the second button.
|
||||
|
||||
## Controller Inheritance Example
|
||||
|
||||
Controller inheritance in angular is based on {@link api/angular.module.NG.$rootScope.Scope Scope} inheritance. Let's
|
||||
Controller inheritance in angular is based on {@link api/angular.module.ng.$rootScope.Scope Scope} inheritance. Let's
|
||||
have a look at an example:
|
||||
|
||||
<pre>
|
||||
|
||||
@@ -11,8 +11,8 @@ pattern, a scope's properties comprise both the model and the controller methods
|
||||
|
||||
|
||||
### Scope characteristics
|
||||
- Scopes provide APIs ({@link api/angular.module.NG.$rootScope.Scope#$watch $watch}) to observe model mutations.
|
||||
- Scopes provide APIs ({@link api/angular.module.NG.$rootScope.Scope#$apply $apply}) to propagate any model changes
|
||||
- Scopes provide APIs ({@link api/angular.module.ng.$rootScope.Scope#$watch $watch}) to observe model mutations.
|
||||
- Scopes provide APIs ({@link api/angular.module.ng.$rootScope.Scope#$apply $apply}) to propagate any model changes
|
||||
through the system into the view from outside of the "Angular realm" (controllers, services,
|
||||
Angular event handlers).
|
||||
- Scopes can be nested to isolate application components while providing access to shared model
|
||||
@@ -27,14 +27,14 @@ Every application has a root scope, which is the ancestor of all other scopes.
|
||||
|
||||
### What is scope used for?
|
||||
|
||||
{@link dev_guide.expressions Expressions} in the view are {@link api/angular.module.NG.$rootScope.Scope#$eval evaluated}
|
||||
{@link dev_guide.expressions Expressions} in the view are {@link api/angular.module.ng.$rootScope.Scope#$eval evaluated}
|
||||
against the current scope. When HTML DOM elements are attached to a scope, expressions in those
|
||||
elements are evaluated against the attached scope.
|
||||
|
||||
There are two kinds of expressions:
|
||||
|
||||
- Binding expressions, which are observations of property changes. Property changes are reflected
|
||||
in the view during the {@link api/angular.module.NG.$rootScope.Scope#$digest digest cycle}.
|
||||
in the view during the {@link api/angular.module.ng.$rootScope.Scope#$digest digest cycle}.
|
||||
- Action expressions, which are expressions with side effects. Typically, the side effects cause
|
||||
execution of a method in a controller in response to a user action, such as clicking on a button.
|
||||
|
||||
@@ -57,7 +57,7 @@ A property write will always write to the current scope. This means that a write
|
||||
property within the scope it writes to, as shown in the following example.
|
||||
|
||||
<pre>
|
||||
var root = angular.module.NG.$rootScope.Scope();
|
||||
var root = angular.module.ng.$rootScope.Scope();
|
||||
var child = root.$new();
|
||||
|
||||
root.name = 'angular';
|
||||
@@ -73,25 +73,25 @@ expect(root.name).toEqual('angular');
|
||||
### Scope life cycle
|
||||
1. **Creation**
|
||||
|
||||
* The root scope is created by the {@link api/angular.module.NG.$rootScope $rootScope} service.
|
||||
* To create a child scopes, you should call {@link api/angular.module.NG.$rootScope.Scope#$new parentScope.$new()}.
|
||||
* The root scope is created by the {@link api/angular.module.ng.$rootScope $rootScope} service.
|
||||
* To create a child scopes, you should call {@link api/angular.module.ng.$rootScope.Scope#$new parentScope.$new()}.
|
||||
|
||||
2. **Watcher registration**
|
||||
|
||||
Watcher registration can happen at any time and on any scope (root or child) via {@link
|
||||
api/angular.module.NG.$rootScope.Scope#$watch scope.$watch()} API.
|
||||
api/angular.module.ng.$rootScope.Scope#$watch scope.$watch()} API.
|
||||
|
||||
3. **Model mutation**
|
||||
|
||||
For mutations to be properly observed, you should make them only within the execution of the
|
||||
function passed into {@link api/angular.module.NG.$rootScope.Scope#$apply scope.$apply()} call. (Angular apis do this
|
||||
function passed into {@link api/angular.module.ng.$rootScope.Scope#$apply scope.$apply()} call. (Angular apis do this
|
||||
implicitly, so no extra `$apply` call is needed when doing synchronous work in controllers, or
|
||||
asynchronous work with {@link api/angular.module.NG.$xhr $xhr} or {@link api/angular.module.NG.$defer
|
||||
asynchronous work with {@link api/angular.module.ng.$xhr $xhr} or {@link api/angular.module.ng.$defer
|
||||
$defer} services.
|
||||
|
||||
4. **Mutation observation**
|
||||
|
||||
At the end of each `$apply` call {@link api/angular.module.NG.$rootScope.Scope#$digest $digest} cycle is started on
|
||||
At the end of each `$apply` call {@link api/angular.module.ng.$rootScope.Scope#$digest $digest} cycle is started on
|
||||
the root scope, which then propagates throughout all child scopes.
|
||||
|
||||
During the `$digest` cycle, all `$watch-ers` expressions or functions are checked for model
|
||||
@@ -100,7 +100,7 @@ mutation and if a mutation is detected, the `$watch-er` listener is called.
|
||||
5. **Scope destruction**
|
||||
|
||||
When child scopes are no longer needed, it is the responsibility of the child scope creator to
|
||||
destroy them via {@link api/angular.module.NG.$rootScope.Scope#$destroy scope.$destroy()} API. This will stop
|
||||
destroy them via {@link api/angular.module.ng.$rootScope.Scope#$destroy scope.$destroy()} API. This will stop
|
||||
propagation of `$digest` calls into the child scope and allow for memory used by the child scope
|
||||
models to be reclaimed by the garbage collector.
|
||||
|
||||
@@ -118,22 +118,22 @@ element.
|
||||
api/angular.directive directives} against the DOM template. The directives usually fall into one of
|
||||
two categories:
|
||||
- Observing {@link api/angular.directive directives}, such as double-curly expressions
|
||||
`{{expression}}`, register listeners using the {@link api/angular.module.NG.$rootScope.Scope#$watch $watch()} method.
|
||||
`{{expression}}`, register listeners using the {@link api/angular.module.ng.$rootScope.Scope#$watch $watch()} method.
|
||||
This type of directive needs to be notified whenever the expression changes so that it can update
|
||||
the view.
|
||||
- Listener directives, such as {@link api/angular.directive.ng:click ng:click}, register a
|
||||
listener with the DOM. When the DOM listener fires, the directive executes the associated
|
||||
expression and updates the view using the {@link api/angular.module.NG.$rootScope.Scope#$apply $apply()} method.
|
||||
expression and updates the view using the {@link api/angular.module.ng.$rootScope.Scope#$apply $apply()} method.
|
||||
3. When an external event (such as a user action, timer or XHR) is received, the associated {@link
|
||||
dev_guide.expressions expression} must be applied to the scope through the {@link
|
||||
api/angular.module.NG.$rootScope.Scope#$apply $apply()} method so that all listeners are updated correctly.
|
||||
api/angular.module.ng.$rootScope.Scope#$apply $apply()} method so that all listeners are updated correctly.
|
||||
|
||||
|
||||
### Directives that create scopes
|
||||
In most cases, {@link api/angular.directive directives} and scopes interact but do not create new
|
||||
instances of scope. However, some directives, such as {@link api/angular.directive.ng:controller
|
||||
ng:controller} and {@link api/angular.widget.@ng:repeat ng:repeat}, create new child scopes using
|
||||
the {@link api/angular.module.NG.$rootScope.Scope#$new $new()} method and then attach the child scope to the
|
||||
the {@link api/angular.module.ng.$rootScope.Scope#$new $new()} method and then attach the child scope to the
|
||||
corresponding DOM element. You can retrieve a scope for any DOM element by using an
|
||||
`angular.element(aDomElement).scope()` method call.)
|
||||
|
||||
@@ -143,13 +143,13 @@ Scopes and controllers interact with each other in the following situations:
|
||||
- Controllers use scopes to expose controller methods to templates (see {@link
|
||||
api/angular.directive.ng:controller ng:controller}).
|
||||
- Controllers define methods (behavior) that can mutate the model (properties on the scope).
|
||||
- Controllers may register {@link api/angular.module.NG.$rootScope.Scope#$watch watches} on the model. These watches
|
||||
- Controllers may register {@link api/angular.module.ng.$rootScope.Scope#$watch watches} on the model. These watches
|
||||
execute immediately after the controller behavior executes, but before the DOM gets updated.
|
||||
|
||||
See the {@link dev_guide.mvc.understanding_controller controller docs} for more information.
|
||||
|
||||
### Updating scope properties
|
||||
You can update a scope by calling its {@link api/angular.module.NG.$rootScope.Scope#$apply $apply()} method with an
|
||||
You can update a scope by calling its {@link api/angular.module.ng.$rootScope.Scope#$apply $apply()} method with an
|
||||
expression or a function as the function argument. However it is typically not necessary to do this
|
||||
explicitly. In most cases, angular intercepts all external events (such as user interactions, XHRs,
|
||||
and timers) and wraps their callbacks into the `$apply()` method call on the scope object for you
|
||||
@@ -172,8 +172,8 @@ doesn't need to worry about propagating the `$digest` call from the parent scope
|
||||
This happens automatically.
|
||||
|
||||
## Scopes in unit-testing
|
||||
You can create scopes, including the root scope, in tests using the {@link api/angular.module.NG.$rootScope.Scope
|
||||
angular.module.NG.$rootScope.Scope()} API. This allows you to mimic the run-time environment and have full control over
|
||||
You can create scopes, including the root scope, in tests using the {@link api/angular.module.ng.$rootScope.Scope
|
||||
angular.module.ng.$rootScope.Scope()} API. This allows you to mimic the run-time environment and have full control over
|
||||
the life cycle of the scope so that you can assert correct model transitions. Since these scopes
|
||||
are created outside the normal compilation process, their life cycles must be managed by the test.
|
||||
|
||||
@@ -183,7 +183,7 @@ within the unit-tests.
|
||||
|
||||
<pre>
|
||||
// example of a test
|
||||
var scope = angular.module.NG.$rootScope.Scope();
|
||||
var scope = angular.module.ng.$rootScope.Scope();
|
||||
scope.$watch('name', function(scope, name){
|
||||
scope.greeting = 'Hello ' + name + '!';
|
||||
});
|
||||
@@ -221,5 +221,5 @@ it('should allow override of providers', inject(
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$rootScope.Scope Angular Scope API}
|
||||
* {@link api/angular.module.ng.$rootScope.Scope Angular Scope API}
|
||||
|
||||
|
||||
@@ -13,15 +13,15 @@ the contexts in which Angular creates data-bindings between the model and the vi
|
||||
|
||||
In addition to providing the context in which data is evaluated, Angular scope objects watch for
|
||||
model changes. The scope objects also notify all components interested in any model changes (for
|
||||
example, functions registered through {@link api/angular.module.NG.$rootScope.Scope#$watch $watch}, bindings created by
|
||||
example, functions registered through {@link api/angular.module.ng.$rootScope.Scope#$watch $watch}, bindings created by
|
||||
{@link api/angular.directive.ng:bind ng:bind}, or HTML input elements).
|
||||
|
||||
Angular scope objects:
|
||||
|
||||
* Link the model, controller and view template together.
|
||||
* Provide the mechanism to watch for model changes ({@link api/angular.module.NG.$rootScope.Scope#$watch $watch}).
|
||||
* Apply model changes to the system ({@link api/angular.module.NG.$rootScope.Scope#$apply $apply}).
|
||||
* Provide the context in which expressions are evaluated ({@link api/angular.module.NG.$rootScope.Scope#$eval $eval}).
|
||||
* Provide the mechanism to watch for model changes ({@link api/angular.module.ng.$rootScope.Scope#$watch $watch}).
|
||||
* Apply model changes to the system ({@link api/angular.module.ng.$rootScope.Scope#$apply $apply}).
|
||||
* Provide the context in which expressions are evaluated ({@link api/angular.module.ng.$rootScope.Scope#$eval $eval}).
|
||||
|
||||
|
||||
## Related Topics
|
||||
@@ -31,5 +31,5 @@ Angular scope objects:
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$rootScope.Scope Angular Scope API}
|
||||
* {@link api/angular.module.ng.$rootScope.Scope Angular Scope API}
|
||||
|
||||
|
||||
@@ -63,4 +63,4 @@ The following illustration shows the DOM and angular scopes for the example abov
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$rootScope.Scope Angular Scope API}
|
||||
* {@link api/angular.module.ng.$rootScope.Scope Angular Scope API}
|
||||
|
||||
@@ -89,7 +89,8 @@ setter methods that allow you to get or change the current URL in the browser.
|
||||
## $location service configuration
|
||||
|
||||
To configure the `$location` service, retrieve the
|
||||
{@link api/angular.module.NG.$locationProvider $locationProvider} and set the parameters as follows:
|
||||
{@link api/angular.module.ng.$locationProvider $locationProvider} and set the parameters as follows:
|
||||
|
||||
|
||||
- **html5Mode(mode)**: {boolean}<br />
|
||||
`true` - see HTML5 mode<br />
|
||||
@@ -133,7 +134,7 @@ current URL without creating a new browser history record you can call:
|
||||
</pre>
|
||||
|
||||
Note that the setters don't update `window.location` immediately. Instead, `$location` service is
|
||||
aware of the {@link api/angular.module.NG.$rootScope.Scope scope} life-cycle and coalesces multiple `$location`
|
||||
aware of the {@link api/angular.module.ng.$rootScope.Scope scope} life-cycle and coalesces multiple `$location`
|
||||
mutations into one "commit" to the `window.location` object during the scope `$digest` phase. Since
|
||||
multiple changes to the $location's state will be pushed to the browser as a single change, it's
|
||||
enough to call the `replace()` method just once to make the entire "commit" a replace operation
|
||||
@@ -487,11 +488,11 @@ In this examples we use `<base href="/base/index.html" />`
|
||||
|
||||
The `$location` service allows you to change only the URL; it does not allow you to reload the
|
||||
page. When you need to change the URL and reload the page or navigate to a different page, please
|
||||
use a lower level API, {@link api/angular.module.NG.$window $window.location.href}.
|
||||
use a lower level API, {@link api/angular.module.ng.$window $window.location.href}.
|
||||
|
||||
## Using $location outside of the scope life-cycle
|
||||
|
||||
`$location` knows about Angular's {@link api/angular.module.NG.$rootScope.Scope scope} life-cycle. When a URL changes in
|
||||
`$location` knows about Angular's {@link api/angular.module.ng.$rootScope.Scope scope} life-cycle. When a URL changes in
|
||||
the browser it updates the `$location` and calls `$apply` so that all $watchers / $observers are
|
||||
notified.
|
||||
When you change the `$location` inside the `$digest` phase everything is ok; `$location` will
|
||||
@@ -511,7 +512,7 @@ hashPrefix.
|
||||
# Testing with the $location service
|
||||
|
||||
When using `$location` service during testing, you are outside of the angular's {@link
|
||||
api/angular.module.NG.$rootScope.Scope scope} life-cycle. This means it's your responsibility to call `scope.$apply()`.
|
||||
api/angular.module.ng.$rootScope.Scope scope} life-cycle. This means it's your responsibility to call `scope.$apply()`.
|
||||
|
||||
<pre>
|
||||
describe('serviceUnderTest', function() {
|
||||
@@ -629,7 +630,7 @@ this.$watch('$location.path()', function(scope, path) {
|
||||
|
||||
# Related API
|
||||
|
||||
* {@link api/angular.module.NG.$location $location API}
|
||||
* {@link api/angular.module.ng.$location $location API}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ While angular offers several useful services, for any nontrivial application you
|
||||
to write your own custom services. To do this you begin by registering a service factory function
|
||||
that angular's DI will use to create the service object when it is needed.
|
||||
|
||||
The `angular.module.NG` method accepts three parameters:
|
||||
The `angular.module.ng` method accepts three parameters:
|
||||
|
||||
- `{string} name` - Name of the service.
|
||||
- `{function()} factory` - Factory function(called just once by DI).
|
||||
@@ -32,7 +32,7 @@ stores all notifications; after the third one, the service displays all of the n
|
||||
window alert.
|
||||
|
||||
<pre>
|
||||
angular.module.NG('notify', function(win) {
|
||||
angular.module.ng('notify', function(win) {
|
||||
var msgs = [];
|
||||
return function(msg) {
|
||||
msgs.push(msg);
|
||||
@@ -55,4 +55,4 @@ window alert.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Angular Service API}
|
||||
* {@link api/angular.module.ng Angular Service API}
|
||||
|
||||
@@ -77,4 +77,4 @@ it('should test service', function() {
|
||||
|
||||
## Related API
|
||||
|
||||
{@link api/angular.module.NG Angular Service API}
|
||||
{@link api/angular.module.ng Angular Service API}
|
||||
|
||||
@@ -19,7 +19,7 @@ provided by angular's web framework:
|
||||
*
|
||||
* @param {*} message Message to be logged.
|
||||
*/
|
||||
angular.module.NG('batchLog', function($defer, $log) {
|
||||
angular.module.ng('batchLog', function($defer, $log) {
|
||||
var messageQueue = [];
|
||||
|
||||
function log() {
|
||||
@@ -43,7 +43,7 @@ angular.module.NG('batchLog', function($defer, $log) {
|
||||
* routeTemplateMonitor monitors each $route change and logs the current
|
||||
* template via the batchLog service.
|
||||
*/
|
||||
angular.module.NG('routeTemplateMonitor', function($route, batchLog) {
|
||||
angular.module.ng('routeTemplateMonitor', function($route, batchLog) {
|
||||
this.$on('$afterRouteChange', function() {
|
||||
batchLog($route.current ? $route.current.template : null);
|
||||
});
|
||||
@@ -52,10 +52,10 @@ angular.module.NG('routeTemplateMonitor', function($route, batchLog) {
|
||||
|
||||
Things to notice in this example:
|
||||
|
||||
* The `batchLog` service depends on the built-in {@link api/angular.module.NG.$defer $defer} and
|
||||
{@link api/angular.module.NG.$log $log} services, and allows messages to be logged into the
|
||||
* The `batchLog` service depends on the built-in {@link api/angular.module.ng.$defer $defer} and
|
||||
{@link api/angular.module.ng.$log $log} services, and allows messages to be logged into the
|
||||
`console.log` in batches.
|
||||
* The `routeTemplateMonitor` service depends on the built-in {@link api/angular.module.NG.$route
|
||||
* The `routeTemplateMonitor` service depends on the built-in {@link api/angular.module.ng.$route
|
||||
$route} service as well as our custom `batchLog` service.
|
||||
* The `routeTemplateMonitor` service is declared to be eager, so that it is started as soon as the
|
||||
application starts.
|
||||
@@ -80,5 +80,5 @@ order to inject.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Angular Service API}
|
||||
* {@link api/angular.module.ng Angular Service API}
|
||||
* {@link api/angular.injector Angular Injector API}
|
||||
|
||||
@@ -19,4 +19,4 @@ most often used with {@link dev_guide.di dependency injection}, also a key featu
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Angular Service API}
|
||||
* {@link api/angular.module.ng Angular Service API}
|
||||
|
||||
@@ -29,7 +29,7 @@ which happens when the angular {@link dev_guide.bootstrap application initialize
|
||||
To override the default, you can request that a service is eagerly instantiated as follows:
|
||||
|
||||
<pre>
|
||||
angular.module.NG('service id', function() {
|
||||
angular.module.ng('service id', function() {
|
||||
var shinyNewServiceInstance;
|
||||
//factory function body that constructs shinyNewServiceInstance
|
||||
return shinyNewServiceInstance;
|
||||
@@ -65,4 +65,4 @@ important.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Angular Service API}
|
||||
* {@link api/angular.module.ng Angular Service API}
|
||||
|
||||
@@ -11,7 +11,7 @@ var mock, notify;
|
||||
|
||||
beforeEach(function() {
|
||||
mock = {alert: jasmine.createSpy()};
|
||||
notify = angular.module.NG('notify')(mock);
|
||||
notify = angular.module.ng('notify')(mock);
|
||||
});
|
||||
|
||||
it('should not alert first two notifications', function() {
|
||||
@@ -53,6 +53,6 @@ it('should clear messages after alert', function() {
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Angular Service API}
|
||||
* {@link api/angular.module.ng Angular Service API}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
@description
|
||||
|
||||
Angular services are singletons that carry out specific tasks common to web apps, such as the
|
||||
{@link api/angular.module.NG.$xhr $xhr service} that provides low level access to the browser's
|
||||
{@link api/angular.module.ng.$xhr $xhr service} that provides low level access to the browser's
|
||||
`XMLHttpRequest` object.
|
||||
|
||||
To use an angular service, you identify it as a dependency for the dependent (a controller, or
|
||||
@@ -33,5 +33,5 @@ above). You can also create your own custom services.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG Angular Service API}
|
||||
* {@link api/angular.module.ng Angular Service API}
|
||||
* {@link api/angular.injector Injector API}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@name Developer Guide: Templates: Filters: Creating Angular Filters
|
||||
@description
|
||||
|
||||
Writing your own filter is very easy: just define a JavaScript function on the `angular.module.NG.$filter`
|
||||
Writing your own filter is very easy: just define a JavaScript function on the `angular.module.ng.$filter`
|
||||
object.
|
||||
The framework passes in the input value as the first argument to your function. Any filter
|
||||
arguments are passed in as additional function arguments.
|
||||
@@ -64,4 +64,4 @@ angular.module.MyReverseModule = function MyModule($filterProvider) {
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$filter Angular Filter API}
|
||||
* {@link api/angular.module.ng.$filter Angular Filter API}
|
||||
|
||||
@@ -11,7 +11,7 @@ displaying it to the user. You can pass expressions through a chain of filters l
|
||||
|
||||
name | uppercase
|
||||
|
||||
The expression evaluator simply passes the value of name to `angular.module.NG.$filter.uppercase()`.
|
||||
The expression evaluator simply passes the value of name to `angular.module.ng.$filter.uppercase()`.
|
||||
|
||||
In addition to formatting data, filters can also modify the DOM. This allows filters to handle
|
||||
tasks such as conditionally applying CSS styles to filtered output.
|
||||
@@ -24,4 +24,4 @@ tasks such as conditionally applying CSS styles to filtered output.
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$filter Angular Filter API}
|
||||
* {@link api/angular.module.ng.$filter Angular Filter API}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
@name Developer Guide: Templates: Filters: Using Angular Filters
|
||||
@description
|
||||
|
||||
Filters can be part of any {@link api/angular.module.NG.$rootScope.Scope} evaluation but are typically used to format
|
||||
Filters can be part of any {@link api/angular.module.ng.$rootScope.Scope} evaluation but are typically used to format
|
||||
expressions in bindings in your templates:
|
||||
|
||||
{{ expression | filter }}
|
||||
@@ -37,4 +37,4 @@ argument that specifies how many digits to display to the right of the decimal p
|
||||
|
||||
## Related API
|
||||
|
||||
* {@link api/angular.module.NG.$filter Angular Filter API}
|
||||
* {@link api/angular.module.ng.$filter Angular Filter API}
|
||||
|
||||
@@ -43,7 +43,7 @@ and {@link dev_guide.expressions expressions}:
|
||||
In a simple single-page app, the template consists of HTML, CSS, and angular directives contained
|
||||
in just one HTML file (usually `index.html`). In a more complex app, you can display multiple views
|
||||
within one main page using "partials", which are segments of template located in separate HTML
|
||||
files. You "include" the partials in the main page using the {@link api/angular.module.NG.$route
|
||||
files. You "include" the partials in the main page using the {@link api/angular.module.ng.$route
|
||||
$route} service in conjunction with the {@link api/angular.widget.ng:view ng:view} directive. An
|
||||
example of this technique is shown in the {@link tutorial/ angular tutorial}, in steps seven and
|
||||
eight.
|
||||
|
||||
@@ -247,16 +247,16 @@ that such a test tells a story, rather then asserting random bits which don't se
|
||||
|
||||
|
||||
## Filters
|
||||
{@link api/angular.module.NG.$filter Filters} are functions which transform the data into user readable
|
||||
{@link api/angular.module.ng.$filter Filters} are functions which transform the data into user readable
|
||||
format. They are important because they remove the formatting responsibility from the application
|
||||
logic, further simplifying the application logic.
|
||||
|
||||
<pre>
|
||||
angular.module.NG.$filter('length', function(text){
|
||||
angular.module.ng.$filter('length', function(text){
|
||||
return (''+(text||'')).length;
|
||||
});
|
||||
|
||||
var length = angular.module.NG.$filter('length');
|
||||
var length = angular.module.ng.$filter('length');
|
||||
expect(length(null)).toEqual(0);
|
||||
expect(length('abc')).toEqual(3);
|
||||
</pre>
|
||||
|
||||
@@ -68,7 +68,7 @@ manipulate the DOM.
|
||||
### What is testability like in angular?
|
||||
|
||||
Very testable. It has an integrated dependency injection framework. See
|
||||
{@link api/angular.module.NG service} for details.
|
||||
{@link api/angular.module.ng service} for details.
|
||||
|
||||
### How can I learn more about angular?
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ contained in the template, data model, and controller, to keep models and views
|
||||
sync. Any changes made to the model are reflected in the view; any changes that occur in the view
|
||||
are reflected in the model.
|
||||
|
||||
To learn more about Angular scopes, see the {@link api/angular.module.NG.$rootScope.Scope angular scope documentation}.
|
||||
To learn more about Angular scopes, see the {@link api/angular.module.ng.$rootScope.Scope angular scope documentation}.
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
@@ -43,7 +43,7 @@ __`app/index.html`:__
|
||||
...
|
||||
</pre>
|
||||
|
||||
We added a standard HTML `<input>` tag and used angular's {@link api/angular.module.NG.$filter.filter $filter}
|
||||
We added a standard HTML `<input>` tag and used angular's {@link api/angular.module.ng.$filter.filter $filter}
|
||||
function to process the input for the `ng:repeater`.
|
||||
|
||||
This lets a user enter search criteria and immediately see the effects of their search on the phone
|
||||
@@ -59,7 +59,7 @@ the DOM to reflect the current state of the model.
|
||||
|
||||
<img src="img/tutorial/tutorial_03_final.png">
|
||||
|
||||
* Use of `$filter`. The {@link api/angular.module.NG.$filter.filter $filter} method uses the `query` value to
|
||||
* Use of `$filter`. The {@link api/angular.module.ng.$filter.filter $filter} method uses the `query` value to
|
||||
create a new array that contains only those records that match the `query`.
|
||||
|
||||
`ng:repeat` automatically updates the view in response to the changing number of phones returned
|
||||
|
||||
@@ -54,9 +54,9 @@ two provided sorting options.
|
||||
|
||||
<img src="img/tutorial/tutorial_04-06_final.png">
|
||||
|
||||
* We then chained the `$filter` method with {@link api/angular.module.NG.$filter.orderBy `$orderBy`} method to
|
||||
* We then chained the `$filter` method with {@link api/angular.module.ng.$filter.orderBy `$orderBy`} method to
|
||||
further process the input into the repeater. `$orderBy` is a utility method similar to {@link
|
||||
api/angular.module.NG.$filter.filter `$filter`}, but instead of filtering an array, it reorders it.
|
||||
api/angular.module.ng.$filter.filter `$filter`}, but instead of filtering an array, it reorders it.
|
||||
|
||||
Angular creates a two way data-binding between the select element and the `orderProp` model.
|
||||
`orderProp` is then used as the input for the `$orderBy` method.
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
|
||||
Enough of building an app with three phones in a hard-coded dataset! Let's fetch a larger dataset
|
||||
from our server using one of angular's built-in {@link api/angular.module.NG services} called {@link
|
||||
api/angular.module.NG.$xhr $xhr}. We will use angular's {@link guide/dev_guide.di dependency
|
||||
from our server using one of angular's built-in {@link api/angular.module.ng services} called {@link
|
||||
api/angular.module.ng.$xhr $xhr}. We will use angular's {@link guide/dev_guide.di dependency
|
||||
injection (DI)} to provide the service to the `PhoneListCtrl` controller.
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ Following is a sample of the file:
|
||||
|
||||
## Controller
|
||||
|
||||
We'll use angular's {@link api/angular.module.NG.$xhr $xhr} service in our controller to make an HTTP
|
||||
We'll use angular's {@link api/angular.module.ng.$xhr $xhr} service in our controller to make an HTTP
|
||||
request to your web server to fetch the data in the `app/phones/phones.json` file. `$xhr` is just
|
||||
one of several built-in {@link api/angular.module.NG angular services} that handle common operations
|
||||
one of several built-in {@link api/angular.module.ng angular services} that handle common operations
|
||||
in web apps. Angular injects these services for you where you need them.
|
||||
|
||||
Services are managed by angular's {@link guide/dev_guide.di DI subsystem}. Dependency injection
|
||||
@@ -127,7 +127,7 @@ describe('PhoneCat controllers', function() {
|
||||
var scope, $browser, ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
scope = angular.module.NG.$rootScope.Scope();
|
||||
scope = angular.module.ng.$rootScope.Scope();
|
||||
$browser = scope.$service('$browser');
|
||||
|
||||
$browser.xhr.expectGET('phones/phones.json')
|
||||
@@ -140,7 +140,7 @@ describe('PhoneCat controllers', function() {
|
||||
|
||||
We created the controller in the test environment, as follows:
|
||||
|
||||
* We created a root scope object by calling `angular.module.NG.$rootScope.Scope()`
|
||||
* We created a root scope object by calling `angular.module.ng.$rootScope.Scope()`
|
||||
|
||||
* We called `scope.$new(PhoneListCtrl)` to get angular to create the child scope associated with
|
||||
the `PhoneListCtrl` controller
|
||||
@@ -149,7 +149,7 @@ Because our code now uses the `$xhr` service to fetch the phone list data in our
|
||||
we create the `PhoneListCtrl` child scope, we need to tell the testing harness to expect an
|
||||
incoming request from the controller. To do this we:
|
||||
|
||||
* Use the {@link api/angular.module.NG.$rootScope.Scope#$service `$service`} method to retrieve the `$browser` service,
|
||||
* Use the {@link api/angular.module.ng.$rootScope.Scope#$service `$service`} method to retrieve the `$browser` service,
|
||||
a service that angular uses to represent various browser APIs. In tests, angular automatically uses
|
||||
a mock version of this service that allows you to write tests without having to deal with these
|
||||
native APIs and the global state associated with them.
|
||||
|
||||
@@ -34,7 +34,7 @@ template into what we call a "layout template". This is a template that is commo
|
||||
our application. Other "partial templates" are then included into this layout template depending on
|
||||
the current "route" — the view that is currently displayed to the user.
|
||||
|
||||
Application routes in angular are declared via the {@link api/angular.module.NG.$route $route}
|
||||
Application routes in angular are declared via the {@link api/angular.module.ng.$route $route}
|
||||
service. This service makes it easy to wire together controllers, view templates, and the current
|
||||
URL location in the browser. Using this feature we can implement {@link
|
||||
http://en.wikipedia.org/wiki/Deep_linking deep linking}, which lets us utilize the browser's
|
||||
@@ -91,7 +91,7 @@ Note the use of the `:phoneId` parameter in the second route declaration. The `$
|
||||
the route declaration — `'/phones/:phoneId'` — as a template that is matched against the current
|
||||
URL. All variables defined with the `:` notation are extracted into the `$route.current.params` map.
|
||||
|
||||
The `params` alias created in the {@link api/angular.module.NG.$route `$route.onChange`} callback
|
||||
The `params` alias created in the {@link api/angular.module.ng.$route `$route.onChange`} callback
|
||||
allows us to use the `phoneId` property of this map in the `phone-details.html` template.
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ phone in the phone list.
|
||||
Now when you click on a phone on the list, the phone details page with phone-specific information
|
||||
is displayed.
|
||||
|
||||
To implement the phone details view we will use {@link api/angular.module.NG.$xhr $xhr} to fetch our
|
||||
To implement the phone details view we will use {@link api/angular.module.ng.$xhr $xhr} to fetch our
|
||||
data, and we'll flesh out the `phone-details.html` view template.
|
||||
|
||||
The most important changes are listed below. You can see the full diff on {@link
|
||||
|
||||
@@ -25,11 +25,11 @@ GitHub}:
|
||||
## Custom Filter
|
||||
|
||||
In order to create a new filter, simply register your custom filter function with the {@link
|
||||
api/angular.module.NG.$filter `angular.module.NG.$filter`} API.
|
||||
api/angular.module.ng.$filter `angular.module.ng.$filter`} API.
|
||||
|
||||
__`app/js/filters.js`:__
|
||||
<pre>
|
||||
angular.module.NG.$filter('checkmark', function(input) {
|
||||
angular.module.ng.$filter('checkmark', function(input) {
|
||||
return input ? '\u2713' : '\u2718';
|
||||
});
|
||||
</pre>
|
||||
@@ -82,8 +82,8 @@ __`test/unit/filtersSpec.js`:__
|
||||
describe('checkmark filter', function() {
|
||||
|
||||
it('should convert boolean values to unicode checkmark or cross', function() {
|
||||
expect(angular.module.NG.$filter.checkmark(true)).toBe('\u2713');
|
||||
expect(angular.module.NG.$filter.checkmark(false)).toBe('\u2718');
|
||||
expect(angular.module.ng.$filter.checkmark(true)).toBe('\u2713');
|
||||
expect(angular.module.ng.$filter.checkmark(false)).toBe('\u2718');
|
||||
});
|
||||
})
|
||||
</pre>
|
||||
@@ -99,7 +99,7 @@ output.
|
||||
|
||||
# Experiments
|
||||
|
||||
* Let's experiment with some of the {@link api/angular.module.NG.$filter built-in angular filters} and add the
|
||||
* Let's experiment with some of the {@link api/angular.module.ng.$filter built-in angular filters} and add the
|
||||
following bindings to `index.html`:
|
||||
* `{{ "lower cap string" | uppercase }}`
|
||||
* `{{ {foo: "bar", baz: 23} | json }}`
|
||||
|
||||
@@ -14,7 +14,7 @@ In this step, you will improve the way our app fetches data.
|
||||
The last improvement we will make to our app is to define a custom service that represents a {@link
|
||||
http://en.wikipedia.org/wiki/Representational_State_Transfer RESTful} client. Using this client we
|
||||
can make xhr requests for data in an easier way, without having to deal with the lower-level {@link
|
||||
api/angular.module.NG.$xhr $xhr} API, HTTP methods and URLs.
|
||||
api/angular.module.ng.$xhr $xhr} API, HTTP methods and URLs.
|
||||
|
||||
The most important changes are listed below. You can see the full diff on {@link
|
||||
https://github.com/angular/angular-phonecat/compare/step-10...step-11
|
||||
@@ -37,30 +37,30 @@ __`app/index.html`.__
|
||||
|
||||
__`app/js/services.js`.__
|
||||
<pre>
|
||||
angular.module.NG('Phone', function($resource) {
|
||||
angular.module.ng('Phone', function($resource) {
|
||||
return $resource('phones/:phoneId.json', {}, {
|
||||
query: {method: 'GET', params: {phoneId: 'phones'}, isArray: true}
|
||||
});
|
||||
});
|
||||
</pre>
|
||||
|
||||
We used the {@link api/angular.module.NG} API to register a custom service. We passed in the name of
|
||||
We used the {@link api/angular.module.ng} API to register a custom service. We passed in the name of
|
||||
the service - 'Phone' - and a factory function. The factory function is similar to a controller's
|
||||
constructor in that both can declare dependencies via function arguments. The Phone service
|
||||
declared a dependency on the `$resource` service.
|
||||
|
||||
The {@link api/angular.module.NG.$resource `$resource`} service makes it easy to create a {@link
|
||||
The {@link api/angular.module.ng.$resource `$resource`} service makes it easy to create a {@link
|
||||
http://en.wikipedia.org/wiki/Representational_State_Transfer RESTful} client with just a few lines
|
||||
of code. This client can then be used in our application, instead of the lower-level {@link
|
||||
api/angular.module.NG.$xhr $xhr} service.
|
||||
api/angular.module.ng.$xhr $xhr} service.
|
||||
|
||||
|
||||
## Controller
|
||||
|
||||
We simplified our sub-controllers (`PhoneListCtrl` and `PhoneDetailCtrl`) by factoring out the
|
||||
lower-level {@link api/angular.module.NG.$xhr $xhr} service, replacing it with a new service called
|
||||
`Phone`. Angular's {@link api/angular.module.NG.$resource `$resource`} service is easier to use than
|
||||
{@link api/angular.module.NG.$xhr $xhr} for interacting with data sources exposed as RESTful
|
||||
lower-level {@link api/angular.module.ng.$xhr $xhr} service, replacing it with a new service called
|
||||
`Phone`. Angular's {@link api/angular.module.ng.$resource `$resource`} service is easier to use than
|
||||
{@link api/angular.module.ng.$xhr $xhr} for interacting with data sources exposed as RESTful
|
||||
resources. It is also easier now to understand what the code in our controllers is doing.
|
||||
|
||||
__`app/js/controllers.js`.__
|
||||
@@ -116,7 +116,7 @@ We have modified our unit tests to verify that our new service is issuing HTTP r
|
||||
processing them as expected. The tests also check that our controllers are interacting with the
|
||||
service correctly.
|
||||
|
||||
The {@link api/angular.module.NG.$resource $resource} service augments the response object with
|
||||
The {@link api/angular.module.ng.$resource $resource} service augments the response object with
|
||||
methods for updating and deleting the resource. If we were to use the standard `toEqual` matcher,
|
||||
our tests would fail because the test values would not match the responses exactly. To solve the
|
||||
problem, we use a newly-defined `toEqualData` {@link
|
||||
@@ -141,7 +141,7 @@ describe('PhoneCat controllers', function() {
|
||||
var scope, $browser, ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
scope = angular.module.NG.$rootScope.Scope();
|
||||
scope = angular.module.ng.$rootScope.Scope();
|
||||
$browser = scope.$service('$browser');
|
||||
|
||||
$browser.xhr.expectGET('phones/phones.json')
|
||||
@@ -167,12 +167,12 @@ describe('PhoneCat controllers', function() {
|
||||
var scope, $browser, ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
scope = angular.module.NG.$rootScope.Scope();
|
||||
scope = angular.module.ng.$rootScope.Scope();
|
||||
$browser = scope.$service('$browser');
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
scope = angular.module.NG.$rootScope.Scope();
|
||||
scope = angular.module.ng.$rootScope.Scope();
|
||||
$browser = scope.$service('$browser');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user