From 5cd002b9ea0fd2c16ba4a725addcec40f1c12ead Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 10 Oct 2013 11:35:30 -0700 Subject: [PATCH] docs(ngInit): add note on best practices --- src/ng/directive/ngInit.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/ng/directive/ngInit.js b/src/ng/directive/ngInit.js index 2e2177eff182..d8b77c6cd7e0 100644 --- a/src/ng/directive/ngInit.js +++ b/src/ng/directive/ngInit.js @@ -6,8 +6,15 @@ * @restrict AC * * @description - * The `ngInit` directive specifies initialization tasks to be executed - * before the template enters execution mode during bootstrap. + * The `ngInit` directive allows you to evaluate an expression in the + * current scope. + * + *
+ * The only appropriate use of `ngInit` for aliasing special properties of + * {@link api/ng.directive:ngRepeat `ngRepeat`}, as seen in the demo bellow. Besides this case, you + * should use {@link guide/dev_guide.mvc.understanding_controller controllers} rather than `ngInit` + * to initialize values on a scope. + *
* * @element ANY * @param {expression} ngInit {@link guide/expression Expression} to eval. @@ -15,14 +22,26 @@ * @example -
- {{greeting}} {{person}}! -
+ +
+
+
+ list[ {{outerIndex}} ][ {{innerIndex}} ] = {{value}}; +
+
+
- it('should check greeting', function() { - expect(binding('greeting')).toBe('Hello'); - expect(binding('person')).toBe('World'); + it('should alias index positions', function() { + expect(element('.example-init').text()) + .toBe('list[ 0 ][ 0 ] = a;' + + 'list[ 0 ][ 1 ] = b;' + + 'list[ 1 ][ 0 ] = c;' + + 'list[ 1 ][ 1 ] = d;'); });