Commit graph

57 commits

Author SHA1 Message Date
Brian Ford
56d0917799 docs(guide/directive): link to directives API from the top of the page 2013-11-06 09:50:56 -08:00
Michal Bendowski
e196413df6 docs(guide/directive): fix transclusion example
The example about transclusion and scopes worked only because the order of `scope` and `element`
arguments is wrong, which means that the `name' property of the scope is not really being updated.
To really work, the directive has to define its own scope, either a new child scope or, as is more
common with transclusion, an isolated scope.

Closes #4774
2013-11-05 13:38:09 +00:00
Gabor Csizmadia
3d4c80cc3e docs(guide/directive): fix myDraggable for zoomed page
If you have zoomed into the page in your browser then the screen coordinate system no longer
matches the page coordinate system.  To ensure that dragged elements work correctly when zoomed
we should use pageX/pageY rather than screenX/screenY.

Closes #4687
2013-10-28 22:01:15 +00:00
Joe Grund
a4d3146ee9 docs(guide/directive): correct reference to myDir rather than ngBind
Closes #4647
2013-10-26 19:47:43 +01:00
Pete Bacon Darwin
fca7bcaf43 docs(guide/directive): improve wording 2013-10-26 19:24:03 +01:00
Joey Organisak
a1806bb460 docs(guide/directive): we are registering directives, not controllers
Closes #4615
2013-10-26 18:51:44 +01:00
Brian Ford
e69c287293 docs(guide/directive,guide/compiler,): drastically improve 2013-10-23 14:17:27 -07:00
Vojta Jina
14438058da docs: correct broken links
This also contains some whitespace corrections by my editor.
2013-10-18 15:35:41 -07:00
sflahave
c106b80c8d docs(guide/directive): improve readability and grammar.
Closes #4386
2013-10-14 07:39:26 +01:00
gdennie
a27b4cf5fd docs(guide/directive): clarify use of binding to scopes
The use of 'angular' as sample text is confusing to the newbie in that they are forced
to confirm that the text 'angular' is not a keyword or otherwise referring to a system
component. This is changed to a more obvious sample text.

The most common form of `ngBind` is moved to the top of the list.

Closes #4237
2013-10-03 23:44:42 +01:00
mtaran-google
333e3375e0 docs(guide/directive): fix indentation in example code
Closes #4241
2013-10-03 23:40:00 +01:00
Ron Waldon
106ee8f850 docs(guide): describe directive replace:false
Previous version stated `replace:false` will append template to element.
Improve description to accurately state that template will _replace_ the
contents of the current element.

Closes #2235, #4166
2013-09-30 22:51:01 +01:00
tomazy
d9dbc6a844 docs(guide): remove duplicated require section 2013-08-29 11:40:56 -07:00
Lucas Galfasó
b3777f275c feat(directive): support as instance syntax
Support controller: 'MyController as my' syntax for directives which publishes
the controller instance to the directive scope.

Support controllerAs syntax to define an alias to the controller within the
directive scope.
2013-07-31 10:30:58 -07:00
Chirayu Krishnappa
bea9422ebf feat($sce): new $sce service for Strict Contextual Escaping.
$sce is a service that provides Strict Contextual Escaping services to AngularJS.

Strict Contextual Escaping
--------------------------

Strict Contextual Escaping (SCE) is a mode in which AngularJS requires
bindings in certain contexts to result in a value that is marked as safe
to use for that context One example of such a context is binding
arbitrary html controlled by the user via ng-bind-html-unsafe.  We
refer to these contexts as privileged or SCE contexts.

As of version 1.2, Angular ships with SCE enabled by default.

Note:  When enabled (the default), IE8 in quirks mode is not supported.
In this mode, IE8 allows one to execute arbitrary javascript by the use
of the expression() syntax.  Refer
http://blogs.msdn.com/b/ie/archive/2008/10/16/ending-expressions.aspx
to learn more about them.  You can ensure your document is in standards
mode and not quirks mode by adding <!doctype html> to the top of your
HTML document.

SCE assists in writing code in way that (a) is secure by default and (b)
makes auditing for security vulnerabilities such as XSS, clickjacking,
etc. a lot easier.

Here's an example of a binding in a privileged context:

  <input ng-model="userHtml">
  <div ng-bind-html-unsafe="{{userHtml}}">

Notice that ng-bind-html-unsafe is bound to {{userHtml}} controlled by
the user.  With SCE disabled, this application allows the user to render
arbitrary HTML into the DIV.  In a more realistic example, one may be
rendering user comments, blog articles, etc. via bindings.  (HTML is
just one example of a context where rendering user controlled input
creates security vulnerabilities.)

For the case of HTML, you might use a library, either on the client side, or on the server side,
to sanitize unsafe HTML before binding to the value and rendering it in the document.

How would you ensure that every place that used these types of bindings was bound to a value that
was sanitized by your library (or returned as safe for rendering by your server?)  How can you
ensure that you didn't accidentally delete the line that sanitized the value, or renamed some
properties/fields and forgot to update the binding to the sanitized value?

To be secure by default, you want to ensure that any such bindings are disallowed unless you can
determine that something explicitly says it's safe to use a value for binding in that
context.  You can then audit your code (a simple grep would do) to ensure that this is only done
for those values that you can easily tell are safe - because they were received from your server,
sanitized by your library, etc.  You can organize your codebase to help with this - perhaps
allowing only the files in a specific directory to do this.  Ensuring that the internal API
exposed by that code doesn't markup arbitrary values as safe then becomes a more manageable task.

In the case of AngularJS' SCE service, one uses $sce.trustAs (and
shorthand methods such as $sce.trustAsHtml, etc.) to obtain values that
will be accepted by SCE / privileged contexts.

In privileged contexts, directives and code will bind to the result of
$sce.getTrusted(context, value) rather than to the value directly.
Directives use $sce.parseAs rather than $parse to watch attribute
bindings, which performs the $sce.getTrusted behind the scenes on
non-constant literals.

As an example, ngBindHtmlUnsafe uses $sce.parseAsHtml(binding
expression).  Here's the actual code (slightly simplified):

  var ngBindHtmlUnsafeDirective = ['$sce', function($sce) {
    return function(scope, element, attr) {
      scope.$watch($sce.parseAsHtml(attr.ngBindHtmlUnsafe), function(value) {
        element.html(value || '');
      });
    };
  }];

Impact on loading templates
---------------------------

This applies both to the ng-include directive as well as templateUrl's
specified by directives.

By default, Angular only loads templates from the same domain and
protocol as the application document.  This is done by calling
$sce.getTrustedResourceUrl on the template URL.  To load templates from
other domains and/or protocols, you may either either whitelist them or
wrap it into a trusted value.

*Please note*:
The browser's Same Origin Policy and Cross-Origin Resource Sharing
(CORS) policy apply in addition to this and may further restrict whether
the template is successfully loaded.  This means that without the right
CORS policy, loading templates from a different domain won't work on all
browsers.  Also, loading templates from file:// URL does not work on
some browsers.

This feels like too much overhead for the developer?
----------------------------------------------------

It's important to remember that SCE only applies to interpolation expressions.

If your expressions are constant literals, they're automatically trusted
and you don't need to call $sce.trustAs on them.
e.g.  <div ng-html-bind-unsafe="'<b>implicitly trusted</b>'"></div> just works.

Additionally, a[href] and img[src] automatically sanitize their URLs and
do not pass them through $sce.getTrusted.  SCE doesn't play a role here.

The included $sceDelegate comes with sane defaults to allow you to load
templates in ng-include from your application's domain without having to
even know about SCE.  It blocks loading templates from other domains or
loading templates over http from an https served document.  You can
change these by setting your own custom whitelists and blacklists for
matching such URLs.

This significantly reduces the overhead.  It is far easier to pay the
small overhead and have an application that's secure and can be audited
to verify that with much more ease than bolting security onto an
application later.
2013-07-25 13:00:35 -07:00
Dean Sofer
454bcfa438 docs(directive): Clarified and cleaned up directive guide
- corrected terminology about how directives use `require`
- added more variations to the DirectiveDefinitionObject
- removed some slightly superfluous text

docs(directive): Minor correction to example to avoid bad practice

Anchor tags should use `ng-href` instead of `href` for interpolation.

docs(directive): Supplementing DDO description

DDO = Directive Definition Object
Tweak recommended here:
https://github.com/angular/angular.js/pull/2888/files#r4664565
2013-07-24 11:34:22 -07:00
Andrew O'Brien
0e9e0af975 docs(guide/directive): make directive controller minification-safe
It is best to emphasize that the "controller" property needs to be min safe

Closes #3125
2013-07-04 00:28:54 +01:00
Michał Gołębiowski
f1b94b4b59 feat(jqLite): switch bind/unbind to more recent jQuery on/off
jQuery switched to a completely new event binding implementation as of
1.7.0, centering around on/off methods instead of previous bind/unbind.
This patch makes jqLite match this implementation while still supporting
previous bind/unbind methods.
2013-06-19 20:53:24 +01:00
sarkasm
0bfa29377d docs(directive): fix typo 2013-06-19 11:50:47 +01:00
Igor Minar
5599b55b04 refactor($route): pull $route and friends into angular-route.js
$route, $routeParams and ngView have been pulled from core angular.js
to angular-route.js/ngRoute module.

This is was done to in order keep the core focused on most commonly
used functionality and allow community routers to be freely used
instead of $route service.

There is no need to panic, angular-route will keep on being supported
by the angular team.

Note: I'm intentionally not fixing tutorial links. Tutorial will need
bigger changes and those should be done when we update tutorial to
1.2.

BREAKING CHANGE: applications that use $route will now need to load
angular-route.js file and define dependency on ngRoute module.

Before:

```
...
<script src="angular.js"></script>
...
var myApp = angular.module('myApp', ['someOtherModule']);
...
```

After:

```
...
<script src="angular.js"></script>
<script src="angular-route.js"></script>
...
var myApp = angular.module('myApp', ['ngRoute', 'someOtherModule']);
...
```

Closes #2804
2013-06-06 17:07:12 -07:00
Jens Rantil
9d19b512e0 docs(guide/directive): clarify directive priority
Fixes #2644.
2013-05-22 21:09:20 +01:00
Jens Rantil
7f597a7509 doc($compile): clarify compile function return value
If a compile function (within a directive) returns a function, it is a
post-link function.

Closes: #2713
2013-05-21 13:17:51 +01:00
Chris Nicola
fc25a443f8 docs(guide:directive): add directive controller usage
Specifically adding a directive controller to the example definition
and how to use declare injectables to avoid minification errors.
2013-04-30 10:47:14 +01:00
@fbiville
fd91d86f0c docs(directive guide) typo in compile/link section
The code snippet shows `{{action.description}}`, the explanation referred to it as `{{action.descriptions}}`.
2013-04-17 14:50:19 +01:00
Luc Morin
63ce1f6265 docs(guide/directives): give more details about directive declaration 2013-04-11 14:00:09 -07:00
Srinivas Kusunam
53abd3fba7 docs(directive): fix typo 2013-03-29 23:22:02 +01:00
Pascal Borreli
9480136d9f docs(*): fixed typos 2013-03-29 23:14:55 +01:00
Arlen Christian Mart Cuss
fe4f0ea262 docs(directive): Fix entity confusion in example. 2013-03-19 10:53:46 -07:00
Niel de la Rouviere
69ef17cce9 docs(directive): minor typo fix
Changed "obeject" to "object"
2013-03-08 23:26:41 +01:00
Luis Ramón López
eb53423a41 feat($compile): support for dynamic template generation
`template` and `templateUrl` properties can now be optionally defined
via a function. This allows templates to be dynamically generated on
the fly.
2013-02-27 17:57:59 -08:00
Luis Ramón López
cf17c6af47 feat($compile): add attribute binding support via ngAttr*
Sometimes is not desirable to use interpolation on attributes because
the user agent parses them before the interpolation takes place. I.e:

<svg>
  <circle cx="{{cx}}" cy="{{cy}}" r="{{r}}"></circle>
</svg>

The snippet throws three browser errors, one for each attribute.

For some attributes, AngularJS fixes that behaviour introducing special
directives like ng-href or ng-src.

This commit is a more general solution that allows prefixing any
attribute with "ng-attr-", "ng:attr:" or "ng_attr_"  so it will
be set only when the binding is done. The prefix is then removed.

Example usage:

<svg>
  <circle ng-attr-cx="{{cx}}" ng-attr-cy="{{cy}}" ng:attr-r="{{r}}"></circle>
</svg>

Closes #1050
Closes #1925
2013-02-27 00:55:40 -08:00
Vineet Kumar
6a612df7de docs(guide/directives): update obsolete doc reference
Replace an obsolete reference to a nonexistent "Creating Widgets"
section with a real link to "Creating Components".
2013-02-25 14:51:52 -08:00
Luis Ramón López
ac899d0da5 feat($compile): '=?' makes '=' binding optional
If you bind using '=' to a non-existant parent property, the compiler
will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception, which is right
because the model doesn't exist.

This enhancement allow to specify that a binding is optional so it
won't complain if the parent property is not defined. In order to mantain
backward compability, the new behaviour must be specified using '=?' instead
of '='. The local property will be undefined is these cases.

Closes #909
Closes #1435
2013-02-25 14:30:54 -08:00
Dylan Pyle
7c6b1e06e8 docs(guide): fix some invalid javascript in directive documentation
Use double quotes to maintain consistency with other HTML
2013-02-14 15:11:04 -08:00
Matt Rohrer
93070f1488 docs(guide): minor grammar fixes 2013-01-17 19:10:46 -05:00
Lucas Galfasó
c0cb9f8c14 doc(directive): Fix typos in dialog widget
Fixes #1799
2013-01-13 10:08:19 +00:00
John Fletcher
6aac69039e docs(guide): minor English corrections to the Directive guide 2012-12-19 20:35:31 +01:00
Miško Hevery
1e13544da8 docs(directive): old syntax 2012-12-18 20:38:43 -08:00
Daniel Luz
5f7054bf5d docs(directive): correct expression, fix typo and re-wrap lines 2012-11-29 19:40:33 +01:00
Kris Jenkins
b21f4a376d docs(): Fix a couple of typos in the documentation 2012-11-21 23:06:59 +01:00
John Hume
e362a510e3 docs(guide/directive): fix typo 2012-11-17 23:49:19 +01:00
Tim Macfarlane
e9253a88b9 docs(guide/directive): fix names in scope '='; easier to grok 2012-11-11 11:20:24 +01:00
Miško Hevery
c6b4ab3548 Update docs/content/guide/directive.ngdoc
docs(directive): fix typo
2012-11-05 19:34:20 -08:00
Miško Hevery
5418564f04 docs(directive): remove reference to old isolation syntax 2012-09-13 11:31:06 -07:00
Brian Ford
f2ebfa16b0 docs(guide): fix directive interpolation example code
Closes #1339
2012-09-11 16:12:41 -07:00
Steve Nicolai
5cb7297a08 doc(devguide) - Fix typos and small grammatical errors in the developer guide. 2012-08-30 16:02:24 -07:00
Jamie Krug
847d2da0f8 fix(docs): Fix typos and improve grammar. 2012-08-30 15:25:21 -07:00
Jamie Krug
dbefd671e4 fix(docs): Fix bad links. 2012-08-30 15:25:20 -07:00
Colin Frei
7e18724dfa doc(directive) correct typos 2012-08-27 15:01:50 -07:00
Vojta Jina
33ad2b4126 docs(guide): hide scenario for directive example
scenario test for this example would be tricky, we need to teach
the runner how to inject mocks first.
2012-07-30 21:21:34 -07:00