From b842642b574a2b95c53b791308ed1bf8ff9d304d Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 15 Jun 2011 22:31:40 -0700 Subject: docs - stripping extra new lines --- .../guide/dev_guide.bootstrap.auto_bootstrap.ngdoc | 29 ---------- .../dev_guide.bootstrap.manual_bootstrap.ngdoc | 10 ---- docs/content/guide/dev_guide.bootstrap.ngdoc | 21 ------- ...e.compiler.directives.creating_directives.ngdoc | 10 ---- .../guide/dev_guide.compiler.directives.ngdoc | 14 ----- .../dev_guide.compiler.directives_widgets.ngdoc | 11 ---- .../dev_guide.compiler.extending_compiler.ngdoc | 11 ---- docs/content/guide/dev_guide.compiler.markup.ngdoc | 24 -------- docs/content/guide/dev_guide.compiler.ngdoc | 8 --- .../dev_guide.compiler.testing_dom_element.ngdoc | 7 --- ...dev_guide.compiler.understanding_compiler.ngdoc | 19 ------ ...v_guide.compiler.widgets.creating_widgets.ngdoc | 20 ------- .../content/guide/dev_guide.compiler.widgets.ngdoc | 11 ---- docs/content/guide/dev_guide.di.ngdoc | 10 ---- .../guide/dev_guide.di.understanding_di.ngdoc | 29 ---------- .../guide/dev_guide.di.using_di_controllers.ngdoc | 12 ---- docs/content/guide/dev_guide.expressions.ngdoc | 49 ---------------- docs/content/guide/dev_guide.introduction.ngdoc | 10 ---- docs/content/guide/dev_guide.mvc.ngdoc | 8 --- .../dev_guide.mvc.understanding_controller.ngdoc | 67 +--------------------- .../guide/dev_guide.mvc.understanding_model.ngdoc | 24 -------- .../guide/dev_guide.mvc.understanding_view.ngdoc | 6 -- docs/content/guide/dev_guide.overview.ngdoc | 50 ---------------- .../dev_guide.scopes.controlling_scopes.ngdoc | 11 ---- docs/content/guide/dev_guide.scopes.ngdoc | 13 ----- .../dev_guide.scopes.understanding_scopes.ngdoc | 14 ----- .../guide/dev_guide.scopes.updating_scopes.ngdoc | 9 --- .../guide/dev_guide.scopes.working_scopes.ngdoc | 13 ----- .../dev_guide.services.creating_services.ngdoc | 12 ---- .../dev_guide.services.injecting_controllers.ngdoc | 12 ---- .../dev_guide.services.managing_dependencies.ngdoc | 14 ----- docs/content/guide/dev_guide.services.ngdoc | 6 -- .../dev_guide.services.registering_services.ngdoc | 16 ------ .../dev_guide.services.testing_services.ngdoc | 14 ----- ...dev_guide.services.understanding_services.ngdoc | 10 ---- docs/content/guide/dev_guide.templates.css.ngdoc | 18 ------ .../guide/dev_guide.templates.databinding.ngdoc | 9 --- ..._guide.templates.filters.creating_filters.ngdoc | 11 ---- .../guide/dev_guide.templates.filters.ngdoc | 10 ---- ...dev_guide.templates.filters.using_filters.ngdoc | 14 ----- ....templates.formatters.creating_formatters.ngdoc | 8 --- .../guide/dev_guide.templates.formatters.ngdoc | 6 -- ...ide.templates.formatters.using_formatters.ngdoc | 3 - docs/content/guide/dev_guide.templates.ngdoc | 12 ---- ....templates.validators.creating_validators.ngdoc | 18 ------ .../guide/dev_guide.templates.validators.ngdoc | 29 ---------- docs/content/guide/dev_guide.unit-testing.ngdoc | 36 ------------ docs/content/guide/index.ngdoc | 19 ------ 48 files changed, 2 insertions(+), 795 deletions(-) (limited to 'docs/content/guide') diff --git a/docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc b/docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc index 1c5e3e26..0b03e19c 100644 --- a/docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc +++ b/docs/content/guide/dev_guide.bootstrap.auto_bootstrap.ngdoc @@ -3,30 +3,23 @@ @name Developer Guide: Initializing Angular: Automatic Initiialization @description - Angular initializes automatically when you load the angular script into your page, specifying angular's `ng:autobind` attribute with no arguments: - ` - From the `name` attribute of the `` tags, angular automatically sets up two-way data binding, and we also demonstrate some easy input validation: - Quantity: Cost: - These input widgets look normal enough, but consider these points: - * When this page loaded, angular bound the names of the input widgets (`qty` and `cost`) to variables of the same name. Think of those variables as the "Model" component of the Model-View-Controller design pattern. @@ -131,13 +107,10 @@ or leave the the input fields blank, the borders turn red color, and the display These `ng:` directives make it easier to implement field validators than coding them in JavaScript, no? Yes. - And finally, the mysterious `{{ double curly braces }}`: - Total: {{qty * cost | currency}} - This notation, `{{ _expression_ }}`, is a bit of built-in angular {@link dev_guide.compiler.markup markup}, a shortcut for displaying data to the user. The expression within curly braces gets transformed by the angular compiler into an angular directive ({@link api/angular.directive.ng:bind @@ -145,36 +118,28 @@ ng:bind}). The expression itself can be a combination of both an expression and dev_guide.templates.filters filter}: `{{ expression | filter }}`. Angular provides filters for formatting display data. - In the example above, the expression in double-curly braces directs angular to, "Bind the data we got from the input widgets to the display, multiply them together, and format the resulting number into output that looks like money." - - # The Angular Philosophy - Angular is built around the belief that declarative code is better than imperative when it comes to building UIs and wiring software components together, while imperative code is excellent for expressing business logic. - Not to put too fine a point on it, but if you wanted to add a new label to your application, you could do so by simply adding text to the HTML template, saving the code, and refreshing your browser: -
Hello
-
Or, as in programmatic systems (like {@link http://code.google.com/webtoolkit/ GWT}), you would
have to write the code and then run the code like this:
-
var label = new Label();
label.setText('Hello');
@@ -182,15 +147,11 @@ label.setClass('label');
parent.addChild(label);
-
That's one line of markup versus four times as much code.
-
-
## More Angular Philosophy
-
* It is a very good idea to decouple DOM manipulation from app logic. This dramatically improves
the testability of the code.
* It is a really, _really_ good idea to regard app testing as equal in importance to app writing.
@@ -201,11 +162,9 @@ development work to progress in parallel, and allows for reuse of both sides.
building an app: from designing the UI, through writing the business logic, to testing.
* It is always good to make common tasks trivial and difficult tasks possible.
-
Now that we're homing in on what angular is, perhaps now would be a good time to list a few things
that angular is not:
-
* It's not a Library. You don't just call its functions, although it does provide you with some
utility APIs.
* It's not a DOM Manipulation Library. Angular uses jQuery to manipulate the DOM behind the scenes,
@@ -225,14 +184,10 @@ changes to the model are automatically reflected in the view. Any changes by the
are automatically reflected in the model.
-
-
# Why You Want Angular
-
Angular frees you from the following pain:
-
* **Registering callbacks:** Registering callbacks clutters your code, making it hard to see the
forest for the trees. Removing common boilerplate code such as callbacks is a good thing. It vastly
reduces the amount of JavaScript coding _you_ have to do, and it makes it easier to see what your
@@ -256,15 +211,11 @@ get started developing features quickly. As a bonus, you get full control over t
process in automated tests.
-
-
# Watch a Presentation About Angular
-
Here is an early presentation on angular, but note that substantial development has occurred since
the talk was given in July of 2010.
-
-
{@link
https://docs.google.com/present/edit?id=0Abz6S2TvsDWSZDQ0OWdjaF8yNTRnODczazdmZg&hl=en&authkey=CO-b7oID
diff --git a/docs/content/guide/dev_guide.scopes.controlling_scopes.ngdoc b/docs/content/guide/dev_guide.scopes.controlling_scopes.ngdoc
index ca63cbc3..cdbad444 100644
--- a/docs/content/guide/dev_guide.scopes.controlling_scopes.ngdoc
+++ b/docs/content/guide/dev_guide.scopes.controlling_scopes.ngdoc
@@ -3,48 +3,37 @@
@name Developer Guide: Scopes: Applying Controllers to Scopes
@description
-
When a controller function is applied to a scope, the scope is augmented with the behavior defined
in the controller. The end result is that the scope behaves as if it were the controller:
-
var scope = angular.scope();
scope.salutation = 'Hello';
scope.name = 'World';
-
expect(scope.greeting).toEqual(undefined);
-
scope.$watch('name', function(){
this.greeting = this.salutation + ' ' + this.name + '!';
});
-
expect(scope.greeting).toEqual('Hello World!');
scope.name = 'Misko';
// scope.$eval() will propagate the change to listeners
expect(scope.greeting).toEqual('Hello World!');
-
scope.$eval();
expect(scope.greeting).toEqual('Hello Misko!');
-
-
## Related Topics
-
* {@link dev_guide.scopes Angular Scope Objects}
* {@link dev_guide.scopes.understanding_scopes Understanding Angular Scopes}
* {@link dev_guide.scopes.working_scopes Working With Angular Scopes}
* {@link dev_guide.scopes.updating_scopes Updating Angular Scopes}
-
## Related API
-
* {@link api/angular.scope Angular Scope API}
diff --git a/docs/content/guide/dev_guide.scopes.ngdoc b/docs/content/guide/dev_guide.scopes.ngdoc
index 730ac348..e9706e2f 100644
--- a/docs/content/guide/dev_guide.scopes.ngdoc
+++ b/docs/content/guide/dev_guide.scopes.ngdoc
@@ -4,48 +4,35 @@
@description
-
-
An angular scope is a JavaScript type defined by angular. Instances of this type are objects that
serve as the context within which all model and controller methods live and get evaluated.
-
Angular links scope objects to specific points in a compiled (processed) template. This linkage
provides the contexts in which angular creates data-bindings between the model and the view. You
can think of angular scope objects as the medium through which the model, view, and controller
communicate.
-
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.scope.$watch $watch}, bindings created by
{@link api/angular.directive.ng:bind ng:bind}, or HTML input elements).
-
Angular scope objects are responsible for:
-
* Gluing the model, controller and view template together.
* Providing the mechanism to watch for model changes ({@link api/angular.scope.$watch}).
* Notifying interested components when the model changes ({@link api/angular.scope.$eval}).
* Providing the context in which all controller functions and angular expressions are evaluated.
-
-
## Related Topics
-
* {@link dev_guide.scopes.understanding_scopes Understanding Scopes}
* {@link dev_guide.scopes.working_scopes Working With Scopes}
* {@link dev_guide.scopes.controlling_scopes Applying Controllers to Scopes}
* {@link dev_guide.scopes.updating_scopes Updating Scopes}
-
## Related API
-
* {@link api/angular.scope Angular Scope API}
-
-
diff --git a/docs/content/guide/dev_guide.scopes.understanding_scopes.ngdoc b/docs/content/guide/dev_guide.scopes.understanding_scopes.ngdoc
index 073c919e..704c9241 100644
--- a/docs/content/guide/dev_guide.scopes.understanding_scopes.ngdoc
+++ b/docs/content/guide/dev_guide.scopes.understanding_scopes.ngdoc
@@ -3,7 +3,6 @@
@name Developer Guide: Scopes: Understanding Scopes
@description
-
Angular automatically creates a root scope during initialization, and attaches it to the page's
root DOM element (usually ``). The root scope object, along with any of its child scope
objects, serves as the infrastructure on which your data model is built. The data model (JavaScript
@@ -11,20 +10,16 @@ objects, arrays, or primitives) is attached to angular scope properties. Angular
values to the DOM where bindings are specified in the template. Angular attaches any controller
functions you have created to their respective scope objects.
-
-
Angular scopes can be nested, so a child scope has a parent scope upstream in the DOM. When you
display an angular expression in the view, angular walks the DOM tree looking in the closest
attached scope object for the specified data. If it doesn't find the data in the closest attached
scope, it looks further up the scope hierarchy until it finds the data.
-
A child scope object inherits properties from its parents. For example, in the following snippet of
code, observe how the value of `name` changes, based on the HTML element it is displayed in:
-
-
-
## Related Topics
-
* {@link dev_guide.scopes Angular Scope Objects}
* {@link dev_guide.scopes.working_scopes Working With Scopes}
* {@link dev_guide.scopes.controlling_scopes Applying Controllers to Scopes}
* {@link dev_guide.scopes.updating_scopes Updating Scopes}
-
## Related API
-
* {@link api/angular.scope Angular Scope API}
diff --git a/docs/content/guide/dev_guide.scopes.updating_scopes.ngdoc b/docs/content/guide/dev_guide.scopes.updating_scopes.ngdoc
index ff6734cc..2d5f1725 100644
--- a/docs/content/guide/dev_guide.scopes.updating_scopes.ngdoc
+++ b/docs/content/guide/dev_guide.scopes.updating_scopes.ngdoc
@@ -3,19 +3,16 @@
@name Developer Guide: Scopes: Updating Scope Properties
@description
-
You can update a scope by calling its {@link api/angular.scope.$eval $eval()} method, but usually
you do not have to do this explicitly. In most cases, angular intercepts all external events (such
as user interactions, XHRs, and timers) and calls the `$eval()` method on the scope object for you
at the right time. The only time you might need to call `$eval()` explicitly is when you create
your own custom widget or service.
-
The reason it is unnecessary to call `$eval()` from within your controller functions when you use
built-in angular widgets and services is because a change in the data model triggers a call to the
`$eval()` method on the scope object where the data model changed.
-
When a user inputs data, angularized widgets copy the data to the appropriate scope and then call
the `$eval()` method on the root scope to update the view. It works this way because scopes are
inherited, and a child scope `$eval()` overrides its parent's `$eval()` method. Updating the whole
@@ -23,25 +20,19 @@ page requires a call to `$eval()` on the root scope as `$root.$eval()`. Similarl
to fetch data from a server is made and the response comes back, the data is written into the model
and then `$eval()` is called to push updates through to the view and any other dependents.
-
A widget that creates scopes (such as {@link api/angular.widget.@ng:repeat ng:repeat}) is
responsible for forwarding `$eval()` calls from the parent to those child scopes. That way, calling
`$eval()` on the root scope will update the whole page. This creates a spreadsheet-like behavior
for your app; the bound views update immediately as the user enters data.
-
-
## Related Documents
-
* {@link dev_guide.scopes Angular Scope Objects}
* {@link dev_guide.scopes.understanding_scopes Understanding Angular Scope Objects}
* {@link dev_guide.scopes.working_scopes Working With Angular Scopes}
* {@link dev_guide.scopes.controlling_scopes Applying Controllers to Scopes}
-
## Related API
-
* {@link api/angular.scope Angular Scope API}
diff --git a/docs/content/guide/dev_guide.scopes.working_scopes.ngdoc b/docs/content/guide/dev_guide.scopes.working_scopes.ngdoc
index ab507e16..8e4503a5 100644
--- a/docs/content/guide/dev_guide.scopes.working_scopes.ngdoc
+++ b/docs/content/guide/dev_guide.scopes.working_scopes.ngdoc
@@ -3,27 +3,22 @@
@name Developer Guide: Scopes: Working With Angular Scopes
@description
-
When you use {@link api/angular.directive.ng:autobind ng:autobind} to bootstrap your application,
angular creates the root scope automatically for you. If you need more control over the
bootstrapping process, or if you need to create a root scope for a test, you can do so using the
{@link api/angular.scope angular.scope()} API.
-
Here is a simple code snippet that demonstrates how to create a scope object, assign model
properties to it, and register listeners to watch for changes to the model properties:
-
var scope = angular.scope();
scope.salutation = 'Hello';
scope.name = 'World';
-
// Verify that greeting is undefined
expect(scope.greeting).toEqual(undefined);
-
// Set up the watcher...
scope.$watch('name', function(){
// when 'name' changes, set 'greeting'...
@@ -31,35 +26,27 @@ this.greeting = this.salutation + ' ' + this.name + '!';
}
);
-
// verify that 'greeting' was set...
expect(scope.greeting).toEqual('Hello World!');
-
// 'name' changed!
scope.name = 'Misko';
-
// scope.$eval() will propagate the change to listeners
expect(scope.greeting).toEqual('Hello World!');
-
scope.$eval();
// verify that '$eval' propagated the change
expect(scope.greeting).toEqual('Hello Misko!');
-
## Related Topics
-
* {@link dev_guide.scopes Angular Scope Objects}
* {@link dev_guide.scopes.understanding_scopes Understanding Scopes}
* {@link dev_guide.scopes.controlling_scopes Applying Controllers to Scopes}
* {@link dev_guide.scopes.updating_scopes Updating Scopes}
-
## Related API
-
* {@link api/angular.scope Angular Scope API}
diff --git a/docs/content/guide/dev_guide.services.creating_services.ngdoc b/docs/content/guide/dev_guide.services.creating_services.ngdoc
index d36c9d67..b75e75a3 100644
--- a/docs/content/guide/dev_guide.services.creating_services.ngdoc
+++ b/docs/content/guide/dev_guide.services.creating_services.ngdoc
@@ -3,15 +3,12 @@
@name Developer Guide: Angular Services: Creating Angular Services
@description
-
While angular offers several useful services, for any nontrivial application you'll find it useful
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.service` method accepts three parameters:
-
- `{string} name` - Name of the service.
- `{function()} factory` - Factory function (called just once by DI).
- `{Object} config` - Configuration object with the following properties:
@@ -22,23 +19,19 @@ array. Defaults to `[]`.
instantiated when angular boots. If false, the service will be lazily instantiated when it is first
requested during instantiation of a dependant. Defaults to `false`.
-
The `this` of the factory function is bound to the root scope of the angular application.
-
All angular services participate in {@link dev_guide.di dependency injection (DI)} by registering
themselves with angular's DI system (injector) under a `name` (id) as well as by declaring
dependencies which need to be provided for the factory function of the registered service. The
ability to swap dependencies for mocks/stubs/dummies in tests allows for services to be highly
testable.
-
Following is an example of a very simple service. This service depends on the `$window` service
(which is passed as a parameter to the factory function) and is just a function. The service simply
stores all notifications; after the third one, the service displays all of the notifications by
window alert.
-
angular.service('notify', function(win) {
var msgs = [];
@@ -53,19 +46,14 @@ window alert.
-
-
## Related Topics
-
* {@link dev_guide.services.understanding_services Understanding Angular Services}
* {@link dev_guide.services.registering_services Registering Angular Services}
* {@link dev_guide.services.managing_dependencies Managing Service Dependencies}
* {@link dev_guide.services.injecting_controllers Injecting Services Into Controllers }
* {@link dev_guide.services.testing_services Testing Angular Services}
-
## Related API
-
* {@link api/angular.service Angular Service API}
diff --git a/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc b/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc
index 75630b32..0046dd7f 100644
--- a/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc
+++ b/docs/content/guide/dev_guide.services.injecting_controllers.ngdoc
@@ -3,11 +3,9 @@
@name Developer Guide: Angular Services: Injecting Services Into Controllers
@description
-
Using services as dependencies for controllers is very similar to using services as dependencies
for another service.
-
Since JavaScript is a dynamic language, DI can't figure out which services to inject by static
types (like in static typed languages). Therefore, you must specify the service name by using the
`$inject` property, which is an array containing strings with names of services to be injected.
@@ -16,7 +14,6 @@ IDs matters: the order of the services in the array will be used when calling th
with injected parameters. The names of parameters in factory function don't matter, but by
convention they match the service IDs.
-
function myController($loc, $log) {
this.firstMethod = function() {
@@ -32,7 +29,6 @@ this.secondMethod = function() {
myController.$inject = ['$location', '$log'];
-
Let's try this simple notify service, injected into the controller...
@@ -73,19 +66,14 @@ it('should test service', function(){ - - ## Related Topics - {@link dev_guide.services.understanding_services Understanding Angular Services} {@link dev_guide.services.creating_services Creating Angular Services} {@link dev_guide.services.registering_services Registering Angular Services} {@link dev_guide.services.managing_dependencies Managing Service Dependencies} {@link dev_guide.services.testing_services Testing Angular Services} - ## Related API - {@link api/angular.service Angular Service API} diff --git a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc index 5adbefae..5f45b001 100644 --- a/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc +++ b/docs/content/guide/dev_guide.services.managing_dependencies.ngdoc @@ -3,20 +3,16 @@ @name Developer Guide: Angular Services: Managing Service Dependencies @description - Angular allows services to declare other services as dependencies needed for construction of their instances. - To declare dependencies, you specify them in the factory function signature and via the `$inject` property, as an array of string identifiers. Optionally the `$inject` property declaration can be dropped (see "Inferring `$inject`" but note that that is currently an experimental feature). - Here is an example of two services that depend on each other, as well as on other services that are provided by angular's web framework: -
/**
* batchLog service allows for messages to be queued in memory and flushed
@@ -27,7 +23,6 @@ provided by angular's web framework:
angular.service('batchLog', function($defer, $log) {
var messageQueue = [];
-
function log() {
if (messageQueue.length) {
$log('batchLog messages: ', messageQueue);
@@ -36,14 +31,12 @@ function log() {
$defer(log, 50000);
}
-
return function(message) {
messageQueue.push(message);
}
}, {$inject: ['$defer', '$log']);
// note how we declared dependency on built-in $defer and $log services above
-
/**
* routeTemplateMonitor monitors each $route change and logs the current
* template via the batchLog service.
@@ -55,10 +48,8 @@ $route.onChange(function() {
}, {$inject: ['$route', 'batchLog'], $eager: true});
-
Things to notice in this example:
-
* The `batchLog` service depends on the built-in {@link api/angular.service.$defer $defer} and
{@link api/angular.service.$log $log} services, and allows messages to be logged into the
`console.log` in batches.
@@ -77,20 +68,15 @@ this array with IDs and their order that the injector uses to determine which se
order to inject.
-
-
## Related Topics
-
* {@link dev_guide.services.understanding_services Understanding Angular Services}
* {@link dev_guide.services.creating_services Creating Angular Services}
* {@link dev_guide.services.registering_services Registering Services}
* {@link dev_guide.services.injecting_controllers Injecting Services Into Controllers }
* {@link dev_guide.services.testing_services Testing Angular Services}
-
## Related API
-
* {@link api/angular.service Angular Service API}
* {@link api/angular.injector Angular Injector API}
diff --git a/docs/content/guide/dev_guide.services.ngdoc b/docs/content/guide/dev_guide.services.ngdoc
index 57449edc..01f747f7 100644
--- a/docs/content/guide/dev_guide.services.ngdoc
+++ b/docs/content/guide/dev_guide.services.ngdoc
@@ -3,18 +3,14 @@
@name Developer Guide: Angular Services
@description
-
Services are a feature that angular brings to client-side web apps from the server side, where
services have been commonly used for a long time. Services in angular apps are substitutable
objects that are wired together using {@link dev_guide.di dependency injection (DI)}. Services are
most often used with {@link dev_guide.di dependency injection}, also a key feature of angular apps.
-
-
## Related Topics
-
* {@link dev_guide.services.understanding_services Understanding Angular Services}
* {@link dev_guide.services.creating_services Creating Angular Services}
* {@link dev_guide.services.registering_services Registering Angular Services}
@@ -22,8 +18,6 @@ most often used with {@link dev_guide.di dependency injection}, also a key featu
* {@link dev_guide.services.injecting_controllers Injecting Services Into Conrollers}
* {@link dev_guide.services.testing_services Testing Angular Services}
-
## Related API
-
* {@link api/angular.service Angular Service API}
diff --git a/docs/content/guide/dev_guide.services.registering_services.ngdoc b/docs/content/guide/dev_guide.services.registering_services.ngdoc
index ea182944..cc50d678 100644
--- a/docs/content/guide/dev_guide.services.registering_services.ngdoc
+++ b/docs/content/guide/dev_guide.services.registering_services.ngdoc
@@ -3,12 +3,10 @@
@name Developer Guide: Angular Services: Registering Angular Services
@description
-
To register a service, register a factory function that creates the service with angular's
Injector. The Injector is exposed as {@link api/angular.scope.$service scope.$service}. The
following pseudo-code shows a simple service registration:
-
angular.service('service id', function() {
var shinyNewServiceInstance;
@@ -17,27 +15,21 @@ angular.service('service id', function() {
});
-
Note that you are not registering a service instance, but rather a factory function that will
create this instance when called.
-
# Instantiating Angular Services
-
A service can be instantiated eagerly or lazily. By default angular instantiates services lazily,
which means that a service will be created only when it is needed for instantiation of a service or
an application component that depends on it. In other words, angular won't instantiate lazy
services unless they are requested directly or indirectly by the application.
-
Eager services on the other hand, are instantiated right after the injector itself is created,
which happens when the angular {@link dev_guide.bootstrap application initializes}.
-
To override the default, you can request that a service is eagerly instantiated as follows:
-
angular.service('service id', function() {
var shinyNewServiceInstance;
@@ -46,12 +38,10 @@ angular.service('service id', function() {
}, {$eager: true});
-
While it is tempting to declare services as eager, only in few cases it is actually useful. If you
are unsure whether to make a service eager, it likely doesn't need to be. To be more specific, a
service should be declared as eager only if it fits one of these scenarios:
-
* Nothing in your application declares this service as its dependency, and this service affects the
state or configuration of the application (e.g. a service that configures `$route` or `$resource`
services)
@@ -60,7 +50,6 @@ because the service passively observes the application and it is optional for ot
components to depend on it. An example of this scenario is a service that monitors and logs
application memory usage.
-
Lastly, it is important to realize that all angular services are applicaiton singletons. This means
that there is only one instance of a given service per injector. Since angular is lethally allergic
to the global state, it is possible to create multiple injectors, each with its own instance of a
@@ -68,19 +57,14 @@ given service, but that is rarely needed, except in tests where this property is
important.
-
-
## Related Topics
-
* {@link dev_guide.services.understanding_services Understanding Angular Services}
* {@link dev_guide.services.creating_services Creating Angular Services}
* {@link dev_guide.services.managing_dependencies Managing Service Dependencies}
* {@link dev_guide.services.injecting_controllers Injecting Services Into Controllers }
* {@link dev_guide.services.testing_services Testing Angular Services}
-
## Related API
-
* {@link api/angular.service Angular Service API}
diff --git a/docs/content/guide/dev_guide.services.testing_services.ngdoc b/docs/content/guide/dev_guide.services.testing_services.ngdoc
index 65e1ab6d..bc860364 100644
--- a/docs/content/guide/dev_guide.services.testing_services.ngdoc
+++ b/docs/content/guide/dev_guide.services.testing_services.ngdoc
@@ -3,29 +3,24 @@
@name Developer Guide: Angular Services: Testing Angular Services
@description
-
Following is a unit test for the service in the example in {@link
dev_guide.services.registering_services Registering Angular Services}. The unit test example uses
Jasmine spy (mock) instead of a real browser alert.
-
var mock, notify;
-
beforeEach(function() {
mock = {alert: jasmine.createSpy()};
notify = angular.service('notify')(mock);
});
-
it('should not alert first two notifications', function() {
notify('one');
notify('two');
expect(mock.alert).not.toHaveBeenCalled();
});
-
it('should alert all after third notification', function() {
notify('one');
notify('two');
@@ -33,7 +28,6 @@ notify('three');
expect(mock.alert).toHaveBeenCalledWith("one\ntwo\nthree");
});
-
it('should clear messages after alert', function() {
notify('one');
notify('two');
@@ -47,24 +41,16 @@ expect(mock.alert.mostRecentCall.args).toEqual(["more\ntwo\nthird"]);
-
-
## Related Topics
-
* {@link dev_guide.services.understanding_services Understanding Angular Services}
* {@link dev_guide.services.creating_services Creating Angular Services}
* {@link dev_guide.services.registering_services Registering Angular Services}
* {@link dev_guide.services.managing_dependencies Managing Service Dependencies}
* {@link dev_guide.services.injecting_controllers Injecting Services Into Conrollers}
-
## Related API
-
* {@link api/angular.service Angular Service API}
-
-
-
diff --git a/docs/content/guide/dev_guide.services.understanding_services.ngdoc b/docs/content/guide/dev_guide.services.understanding_services.ngdoc
index f7afc981..05fafcf6 100644
--- a/docs/content/guide/dev_guide.services.understanding_services.ngdoc
+++ b/docs/content/guide/dev_guide.services.understanding_services.ngdoc
@@ -3,46 +3,36 @@
@name Developer Guide: Angular Services: Understanding Angular Services
@description
-
Angular services are singletons that carry out specific tasks common to web apps, such as the
{@link api/angular.service.$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
another service) that depends on the service. Angular's dependency injection subsystem takes care
of the rest. The angular injector subsystem is in charge of service instantiation, resolution of
dependencies, and provision of dependencies to factory functions as requested.
-
Angular injects dependencies using "constructor" injection (the service is passed in via a factory
function). Because JavaScript is a dynamically typed language, angular's dependency injection
subsystem cannot use static types to identify service dependencies. For this reason a dependent
must explicitly define its dependencies by using the `$inject` property. For example:
-
myController.$inject = ['$location'];
-
The angular web framework provides a set of services for common operations. Like other core angular
variables and identifiers, the built-in services always start with `$` (such as `$xhr` mentioned
above). You can also create your own custom services.
-
-
## Related Topics
-
* {@link dev_guide.di About Angular Dependency Injection}
* {@link dev_guide.services.creating_services Creating Angular Services}
* {@link dev_guide.services.registering_services Registering Angular Services}
* {@link dev_guide.services.managing_dependencies Managing Service Dependencies}
* {@link dev_guide.services.testing_services Testing Angular Services}
-
## Related API
-
* {@link api/angular.service Angular Service API}
* {@link api/angular.injector Injector API}
diff --git a/docs/content/guide/dev_guide.templates.css.ngdoc b/docs/content/guide/dev_guide.templates.css.ngdoc
index 90021b98..e1e54814 100644
--- a/docs/content/guide/dev_guide.templates.css.ngdoc
+++ b/docs/content/guide/dev_guide.templates.css.ngdoc
@@ -4,66 +4,48 @@
@description
-
-
Angular includes built-in CSS classes, which in turn have predefined CSS styles.
-
# Built-in CSS classes
-
* `ng-exception`
-
**Usage:** angular applies this class to a DOM element if that element contains an Expression that
threw an exception when evaluated.
-
**Styling:** The built-in styling of the ng-exception class displays an error message surrounded
by a solid red border, for example:
-
- - ## Related Topics - * {@link dev_guide.templates Angular Templates} * {@link dev_guide.templates.css Working With CSS in Angular} * {@link dev_guide.templates.formatters Angular Formatters} diff --git a/docs/content/guide/dev_guide.templates.databinding.ngdoc b/docs/content/guide/dev_guide.templates.databinding.ngdoc index 1459095e..3bd0ea8f 100644 --- a/docs/content/guide/dev_guide.templates.databinding.ngdoc +++ b/docs/content/guide/dev_guide.templates.databinding.ngdoc @@ -3,16 +3,13 @@ @name Developer Guide: Templates: Data Binding in Angular @description - Data-binding in angular web apps is the automatic syncing of data between the model and view components. The way that angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa. - ## Data Binding in Classical Template Systems -
Most templating systems bind data in only one direction: they merge template and model components
together into a view, as illustrated in the diagram. After the merge occurs, changes to the model
@@ -20,10 +17,8 @@ or related sections of the view are NOT automatically reflected in the view. Wor
that the user makes to the view are not reflected in the model. This means that the developer has
to write code that constantly syncs the view with the model and the model with the view.
-
## Data Binding in Angular Templates
-
The way angular templates works is different, as illustrated in the diagram. They are different
because first the template (which is the uncompiled HTML along with any additional markup or
@@ -33,16 +28,12 @@ the model are propagated to the view. This makes the model always the single-sou
the application state, greatly simplifying the programing model for the developer. You can think of
the view as simply an instant projection of your model.
-
Because the view is just a projection of the model, the controller is completely separated from the
view and unaware of it. This makes testing a snap because it is easy to test your controller in
isolation without the view and the related DOM/browser dependency.
-
-
## Related Topics
-
* {@link dev_guide.scopes Angular Scopes}
* {@link dev_guide.templates Angular Templates}
diff --git a/docs/content/guide/dev_guide.templates.filters.creating_filters.ngdoc b/docs/content/guide/dev_guide.templates.filters.creating_filters.ngdoc
index ca7fa2f2..ebb7d923 100644
--- a/docs/content/guide/dev_guide.templates.filters.creating_filters.ngdoc
+++ b/docs/content/guide/dev_guide.templates.filters.creating_filters.ngdoc
@@ -3,25 +3,20 @@
@name Developer Guide: Templates: Filters: Creating Angular Filters
@description
-
Writing your own filter is very easy: just define a JavaScript function on the `angular.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.
-
You can use these variables in the function:
-
* `this` — The current scope.
* `this.$element` — The DOM element containing the binding. The `$element` variable allows the
filter to manipulate the DOM.
-
The following sample filter reverses a text string. In addition, it conditionally makes the
text upper-case and assigns color.
-
function reverse(text) {
var reversed = [];
@@ -25,7 +22,6 @@ reversed.unshift(text.charAt(i));
return reversed.join('');
}
-
angular.formatter('reverse', {
parse: function(value){
return reverse(value||'').toUpperCase();
@@ -36,7 +32,6 @@ return reverse(value||'').toLowerCase();
});
-
-
diff --git a/docs/content/guide/dev_guide.templates.ngdoc b/docs/content/guide/dev_guide.templates.ngdoc
index 59fed0fc..ca0ca99a 100644
--- a/docs/content/guide/dev_guide.templates.ngdoc
+++ b/docs/content/guide/dev_guide.templates.ngdoc
@@ -3,17 +3,14 @@
@name Developer Guide: Understanding Angular Templates
@description
-
An angular template is the declarative specification that, along with information from the model
and controller, becomes the rendered view that a user sees in the browser. It is the static DOM,
containing HTML, CSS, and angular-specific elements and angular-specific element attributes. The
angular elements and attributes direct angular to add behavior and transform the template DOM into
the dynamic view DOM.
-
These are the types of angular elements and element attributes you can use in a template:
-
* {@link dev_guide.compiler.directives Directive} — An attribute that augments an existing DOM
element.
* {@link dev_guide.compiler.widgets Widget} — A custom DOM element. An example of a built-in widget
@@ -25,16 +22,13 @@ curly brace notation `{{ }}` to bind expressions to elements is built-in angular
* {@link dev_guide.templates.formatters Formatter} — Lets you format the input object into a user
readable view.
-
Note: In addition to declaring the elements above in templates, you can also access these elements
in JavaScript code.
-
The following code snippet shows a simple angular template made up of standard HTML tags along with
angular {@link dev_guide.compiler.directives directives}, {@link dev_guide.compiler.markup markup},
and {@link dev_guide.expressions expressions}:
-
@@ -49,7 +43,6 @@ 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
@@ -59,17 +52,12 @@ example of this technique is shown in the {@link tutorial/ angular tutorial}, in
eight.
-
-
## Related Topics
-
* {@link dev_guide.templates.filters Angular Filters}
* {@link dev_guide.templates.formatters Angular Formatters}
* {@link dev_guide.templates.validators Angular Validators}
-
## Related API
-
* {@link api/index API Reference}
diff --git a/docs/content/guide/dev_guide.templates.validators.creating_validators.ngdoc b/docs/content/guide/dev_guide.templates.validators.creating_validators.ngdoc
index 661ce744..835b0b51 100644
--- a/docs/content/guide/dev_guide.templates.validators.creating_validators.ngdoc
+++ b/docs/content/guide/dev_guide.templates.validators.creating_validators.ngdoc
@@ -4,17 +4,13 @@
@description
-
-
To create a custom validator, you simply add your validator code as a method onto the
`angular.validator` object and provide input(s) for the validator function. Each input provided is
treated as an argument to the validator function. Any additional inputs should be separated by
commas.
-
The following bit of pseudo-code shows how to set up a custom validator:
-
angular.validator('your_validator', function(input [,additional params]) {
[your validation code];
@@ -26,22 +22,17 @@ angular.validator('your_validator', function(input [,additional params]) {
}
-
Note that this validator returns "true" when the user's input is incorrect, as in "Yes, it's true,
there was a problem with that input". If you prefer to provide more information when a validator
detects a problem with input, you can specify an error message in the validator that angular will
display when the user hovers over the input widget.
-
To specify an error message, replace "`return true;`" with an error string, for example:
-
return "Must be a value between 1 and 5!";
-
Following is a sample UPS Tracking Number validator:
-