Skip to content

Commit

Permalink
docs($compileProvider): improve strictComponentBindingsEnabled info
Browse files Browse the repository at this point in the history
Related to angular#16303 
Closes angular#16306
  • Loading branch information
Narretz authored Oct 30, 2017
1 parent c15c8a1 commit 0864f73
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
34 changes: 31 additions & 3 deletions docs/content/error/$compile/missingattr.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@
@fullName Missing required attribute
@description

This error may occur only when `$compileProvider.strictComponentBindingsEnabled` is set to `true`.
Then all attributes mentioned in `bindings` without `?` must be set. If one or more aren't set,
the first one will throw an error.
This error may occur only when {@link $compileProvider#strictComponentBindingsEnabled `$compileProvider.strictComponentBindingsEnabled`} is set to `true`.

If that is the case, then all {@link $compileProvider#component component} controller bindings and
{@link $compileProvider#directive directive} scope / controller bindings that are non-optional,
must be provided when the directive is instantiated.

To make a binding optional, add '?' to the definition.

## Example:

```js

app.component('myTest', {
bindings: {
first: '=?', // optional
second: '='
},
controller: function() {
...
},
template: '...'
});

```

This component will throw `missingattr` for the `second` binding when used as follows:

```html
<my-test></my-test>
```

13 changes: 8 additions & 5 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,16 +1415,19 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* @ngdoc method
* @name $compileProvider#strictComponentBindingsEnabled
*
* @param {boolean=} enabled update the strictComponentBindingsEnabled state if provided, otherwise just return the
* current strictComponentBindingsEnabled state
* @param {boolean=} enabled update the strictComponentBindingsEnabled state if provided,
* otherwise return the current strictComponentBindingsEnabled state.
* @returns {*} current value if used as getter or itself (chaining) if used as setter
*
* @kind function
*
* @description
* Call this method to enable/disable strict component bindings check. If enabled, the compiler will enforce that
* for all bindings of a component that are not set as optional with `?`, an attribute needs to be provided
* on the component's HTML tag.
* Call this method to enable / disable the strict component bindings check. If enabled, the
* compiler will enforce that all scope / controller bindings of a
* {@link $compileProvider#directive directive} / {@link $compileProvider#component component}
* that are not set as optional with `?`, must be provided when the directive is instantiated.
* If not provided, the compiler will throw the
* {@link error/$compile/missingattr $compile:missingattr error}.
*
* The default value is false.
*/
Expand Down

0 comments on commit 0864f73

Please sign in to comment.