Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs($compileProvider): improve strictComponentBindingsEnabled info #16306

Merged
merged 1 commit into from
Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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