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

Commit 7b991f9

Browse files
docs($compile): document the new $onInit controller hook
1 parent ba162d5 commit 7b991f9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/ng/compile.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,18 @@
218218
* definition: `controller: 'myCtrl as myAlias'`.
219219
*
220220
* When an isolate scope is used for a directive (see above), `bindToController: true` will
221-
* allow a component to have its properties bound to the controller, rather than to scope. When the controller
222-
* is instantiated, the initial values of the isolate scope bindings will be available if the controller is not an ES6 class.
221+
* allow a component to have its properties bound to the controller, rather than to scope.
222+
*
223+
* After the controller is instantiated, the initial values of the isolate scope bindings will bound to the controller
224+
* properties. You can access these bindings once they have been initialized by providing a controller method called
225+
* `$onInit`, which is called after all the controllers on an element have been constructed and had their bindings
226+
* initialized.
227+
*
228+
* <div class="alert alert-warning">
229+
* **Deprecation warning:** although bindings for non-ES6 class controllers are currently
230+
* bound to `this` before the controller constructor is called, this use is now deprecated. Please place initialization
231+
* code that relies upon bindings inside a `$onInit` method on the controller, instead.
232+
* </div>
223233
*
224234
* It is also possible to set `bindToController` to an object hash with the same format as the `scope` property.
225235
* This will set up the scope bindings to the controller directly. Note that `scope` can still be used
@@ -255,6 +265,10 @@
255265
* The `$transclude` function also has a method on it, `$transclude.isSlotFilled(slotName)`, which returns
256266
* `true` if the specified slot contains content (i.e. one or more DOM nodes).
257267
*
268+
* The controller can provide the following methods that act as life-cycle hooks:
269+
* * `$onInit` - Called on each controller after all the controllers on an element have been constructed and
270+
* had their bindings initialized. This is a good place to put initialization code for your controller.
271+
*
258272
* #### `require`
259273
* Require another directive and inject its controller as the fourth argument to the linking function. The
260274
* `require` takes a string name (or array of strings) of the directive(s) to pass in. If an array is used, the

0 commit comments

Comments
 (0)