@@ -367,9 +367,12 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
367
367
* Registers a state configuration under a given state name. The stateConfig object
368
368
* has the following acceptable properties.
369
369
*
370
+ * @param {string } name A unique state name, e.g. "home", "about", "contacts".
371
+ * To create a parent/child state use a dot, e.g. "about.sales", "home.newest".
372
+ * @param {object } stateConfig State configuration object.
373
+ * @param {string|function= } stateConfig.template
370
374
* <a id='template'></a>
371
- *
372
- * - **`template`** - {string|function=} - html template as a string or a function that returns
375
+ * html template as a string or a function that returns
373
376
* an html template as a string which should be used by the uiView directives. This property
374
377
* takes precedence over templateUrl.
375
378
*
@@ -378,94 +381,268 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
378
381
* - {array.<object>} - state parameters extracted from the current $location.path() by
379
382
* applying the current state
380
383
*
384
+ * <pre>template:
385
+ * "<h1>inline template definition</h1>" +
386
+ * "<div ui-view></div>"</pre>
387
+ * <pre>template: function(params) {
388
+ * return "<h1>generated template</h1>"; }</pre>
389
+ * </div>
390
+ *
391
+ * @param {string|function= } stateConfig.templateUrl
381
392
* <a id='templateUrl'></a>
382
393
*
383
- * - **`templateUrl`** - {string|function=} - path or function that returns a path to an html
394
+ * path or function that returns a path to an html
384
395
* template that should be used by uiView.
385
396
*
386
397
* If `templateUrl` is a function, it will be called with the following parameters:
387
398
*
388
399
* - {array.<object>} - state parameters extracted from the current $location.path() by
389
400
* applying the current state
390
401
*
391
- * <a id='templateProvider'></a>
402
+ * <pre>templateUrl: "home.html"</pre>
403
+ * <pre>templateUrl: function(params) {
404
+ * return myTemplates[params.pageId]; }</pre>
392
405
*
393
- * - **`templateProvider`** - {function=} - Provider function that returns HTML content
394
- * string.
406
+ * @param {function= } stateConfig.templateProvider
407
+ * <a id='templateProvider'></a>
408
+ * Provider function that returns HTML content string.
409
+ * <pre> templateProvider:
410
+ * function(MyTemplateService, params) {
411
+ * return MyTemplateService.getTemplate(params.pageId);
412
+ * }</pre>
395
413
*
414
+ * @param {string|function= } stateConfig.controller
396
415
* <a id='controller'></a>
397
416
*
398
- * - **`controller`** - {string|function=} - Controller fn that should be associated with newly
417
+ * Controller fn that should be associated with newly
399
418
* related scope or the name of a registered controller if passed as a string.
419
+ * Optionally, the ControllerAs may be declared here.
420
+ * <pre>controller: "MyRegisteredController"</pre>
421
+ * <pre>controller:
422
+ * "MyRegisteredController as fooCtrl"}</pre>
423
+ * <pre>controller: function($scope, MyService) {
424
+ * $scope.data = MyService.getData(); }</pre>
400
425
*
426
+ * @param {function= } stateConfig.controllerProvider
401
427
* <a id='controllerProvider'></a>
402
428
*
403
- * - **`controllerProvider`** - {function=} - Injectable provider function that returns
404
- * the actual controller or string.
429
+ * Injectable provider function that returns the actual controller or string.
430
+ * <pre>controllerProvider:
431
+ * function(MyResolveData) {
432
+ * if (MyResolveData.foo)
433
+ * return "FooCtrl"
434
+ * else if (MyResolveData.bar)
435
+ * return "BarCtrl";
436
+ * else return function($scope) {
437
+ * $scope.baz = "Qux";
438
+ * }
439
+ * }</pre>
405
440
*
441
+ * @param {string= } stateConfig.controllerAs
406
442
* <a id='controllerAs'></a>
407
443
*
408
- * - **`controllerAs`** – {string=} – A controller alias name. If present the controller will be
444
+ * A controller alias name. If present the controller will be
409
445
* published to scope under the controllerAs name.
446
+ * <pre>controllerAs: "myCtrl"</pre>
410
447
*
448
+ * @param {object= } stateConfig.resolve
411
449
* <a id='resolve'></a>
412
450
*
413
- * - **`resolve`** - {object. <string, function>=} - An optional map of dependencies which
451
+ * An optional map <string, function> of dependencies which
414
452
* should be injected into the controller. If any of these dependencies are promises,
415
- * the router will wait for them all to be resolved or one to be rejected before the
416
- * controller is instantiated. If all the promises are resolved successfully, the values
417
- * of the resolved promises are injected and $stateChangeSuccess event is fired. If any
418
- * of the promises are rejected the $stateChangeError event is fired. The map object is:
453
+ * the router will wait for them all to be resolved before the controller is instantiated.
454
+ * If all the promises are resolved successfully, the $stateChangeSuccess event is fired
455
+ * and the values of the resolved promises are injected into any controllers that reference them.
456
+ * If any of the promises are rejected the $stateChangeError event is fired.
457
+ *
458
+ * The map object is:
419
459
*
420
460
* - key - {string}: name of dependency to be injected into controller
421
461
* - factory - {string|function}: If string then it is alias for service. Otherwise if function,
422
462
* it is injected and return value it treated as dependency. If result is a promise, it is
423
463
* resolved before its value is injected into controller.
424
464
*
465
+ * <pre>resolve: {
466
+ * myResolve1:
467
+ * function($http, $stateParams) {
468
+ * return $http.get("/api/foos/"+stateParams.fooID);
469
+ * }
470
+ * }</pre>
471
+ *
472
+ * @param {string= } stateConfig.url
425
473
* <a id='url'></a>
426
474
*
427
- * - **`url`** - {string=} - A url with optional parameters. When a state is navigated or
475
+ * A url fragment with optional parameters. When a state is navigated or
428
476
* transitioned to, the `$stateParams` service will be populated with any
429
477
* parameters that were passed.
430
478
*
431
- * <a id='params'></a>
432
- *
433
- * - **`params`** - {object=} - An array of parameter names or regular expressions. Only
434
- * use this within a state if you are not using url. Otherwise you can specify your
435
- * parameters within the url. When a state is navigated or transitioned to, the
436
- * $stateParams service will be populated with any parameters that were passed.
479
+ * examples:
480
+ * <pre>url: "/home"
481
+ * url: "/users/:userid"
482
+ * url: "/books/{bookid:[a-zA-Z_-]}"
483
+ * url: "/books/{categoryid:int}"
484
+ * url: "/books/{publishername:string}/{categoryid:int}"
485
+ * url: "/messages?before&after"
486
+ * url: "/messages?{before:date}&{after:date}"</pre>
487
+ * url: "/messages/:mailboxid?{before:date}&{after:date}"
437
488
*
489
+ * @param {object= } stateConfig.views
438
490
* <a id='views'></a>
491
+ * an optional map<string, object> which defined multiple views, or targets views
492
+ * manually/explicitly.
439
493
*
440
- * - **`views`** - {object=} - Use the views property to set up multiple views or to target views
441
- * manually/explicitly.
494
+ * Examples:
442
495
*
443
- * <a id='abstract'></a>
496
+ * Targets three named `ui-view`s in the parent state's template
497
+ * <pre>views: {
498
+ * header: {
499
+ * controller: "headerCtrl",
500
+ * templateUrl: "header.html"
501
+ * }, body: {
502
+ * controller: "bodyCtrl",
503
+ * templateUrl: "body.html"
504
+ * }, footer: {
505
+ * controller: "footCtrl",
506
+ * templateUrl: "footer.html"
507
+ * }
508
+ * }</pre>
509
+ *
510
+ * Targets named `ui-view="header"` from grandparent state 'top''s template, and named `ui-view="body" from parent state's template.
511
+ * <pre>views: {
512
+ * 'header@top ': {
513
+ * controller: "msgHeaderCtrl",
514
+ * templateUrl: "msgHeader.html"
515
+ * }, 'body': {
516
+ * controller: "messagesCtrl",
517
+ * templateUrl: "messages.html"
518
+ * }
519
+ * }</pre>
444
520
*
445
- * - **`abstract`** - {boolean=} - An abstract state will never be directly activated,
521
+ * @param {boolean= } [stateConfig.abstract=false]
522
+ * <a id='abstract'></a>
523
+ * An abstract state will never be directly activated,
446
524
* but can provide inherited properties to its common children states.
525
+ * <pre>abstract: true</pre>
447
526
*
527
+ * @param {function= } stateConfig.onEnter
448
528
* <a id='onEnter'></a>
449
529
*
450
- * - **`onEnter`** - {object=} - Callback function for when a state is entered. Good way
530
+ * Callback function for when a state is entered. Good way
451
531
* to trigger an action or dispatch an event, such as opening a dialog.
452
- * If minifying your scripts, make sure to use the `['injection1', 'injection2', function(injection1, injection2){}]` syntax.
532
+ * If minifying your scripts, make sure to explictly annotate this function,
533
+ * because it won't be automatically annotated by your build tools.
534
+ *
535
+ * <pre>onEnter: function(MyService, $stateParams) {
536
+ * MyService.foo($stateParams.myParam);
537
+ * }</pre>
453
538
*
539
+ * @param {function= } stateConfig.onExit
454
540
* <a id='onExit'></a>
455
541
*
456
- * - **`onExit`** - {object=} - Callback function for when a state is exited. Good way to
542
+ * Callback function for when a state is exited. Good way to
457
543
* trigger an action or dispatch an event, such as opening a dialog.
458
- * If minifying your scripts, make sure to use the `['injection1', 'injection2', function(injection1, injection2){}]` syntax.
544
+ * If minifying your scripts, make sure to explictly annotate this function,
545
+ * because it won't be automatically annotated by your build tools.
459
546
*
547
+ * <pre>onExit: function(MyService, $stateParams) {
548
+ * MyService.cleanup($stateParams.myParam);
549
+ * }</pre>
550
+ *
551
+ * @param {boolean= } [stateConfig.reloadOnSearch=true]
460
552
* <a id='reloadOnSearch'></a>
461
553
*
462
- * - **`reloadOnSearch = true`** - {boolean=} - If `false`, will not retrigger the same state
554
+ * If `false`, will not retrigger the same state
463
555
* just because a search/query parameter has changed (via $location.search() or $location.hash()).
464
556
* Useful for when you'd like to modify $location.search() without triggering a reload.
557
+ * <pre>reloadOnSearch: false</pre>
465
558
*
559
+ * @param {object= } stateConfig.data
466
560
* <a id='data'></a>
467
561
*
468
- * - **`data`** - {object=} - Arbitrary data object, useful for custom configuration.
562
+ * Arbitrary data object, useful for custom configuration. The parent state's `data` is
563
+ * prototypally inherited. In other words, adding a data property to a state adds it to
564
+ * the entire subtree via prototypal inheritance.
565
+ *
566
+ * <pre>data: {
567
+ * requiredRole: 'foo'
568
+ * } </pre>
569
+ *
570
+ * @param {object= } stateConfig.params
571
+ * <a id='params'></a>
572
+ *
573
+ * A map which optionally configures parameters declared in the `url`, or
574
+ * defines additional non-url parameters. For each parameter being
575
+ * configured, add a configuration object keyed to the name of the parameter.
576
+ *
577
+ * Each parameter configuration object may contain the following properties:
578
+ *
579
+ * - ** value ** - {object|function=}: specifies the default value for this
580
+ * parameter. This implicitly sets this parameter as optional.
581
+ *
582
+ * When UI-Router routes to a state and no value is
583
+ * specified for this parameter in the URL or transition, the
584
+ * default value will be used instead. If `value` is a function,
585
+ * it will be injected and invoked, and the return value used.
586
+ *
587
+ * *Note*: `undefined` is treated as "no default value" while `null`
588
+ * is treated as "the default value is `null`".
589
+ *
590
+ * *Shorthand*: If you only need to configure the default value of the
591
+ * parameter, you may use a shorthand syntax. In the **`params`**
592
+ * map, instead mapping the param name to a full parameter configuration
593
+ * object, simply set map it to the default parameter value, e.g.:
594
+ *
595
+ * <pre>// define a parameter's default value
596
+ * params: {
597
+ * param1: { value: "defaultValue" }
598
+ * }
599
+ * // shorthand default values
600
+ * params: {
601
+ * param1: "defaultValue",
602
+ * param2: "param2Default"
603
+ * }</pre>
604
+ *
605
+ * - ** array ** - {boolean=}: *(default: false)* If true, the param value will be
606
+ * treated as an array of values. If you specified a Type, the value will be
607
+ * treated as an array of the specified Type. Note: query parameter values
608
+ * default to a special `"auto"` mode.
609
+ *
610
+ * For query parameters in `"auto"` mode, if multiple values for a single parameter
611
+ * are present in the URL (e.g.: `/foo?bar=1&bar=2&bar=3`) then the values
612
+ * are mapped to an array (e.g.: `{ foo: [ '1', '2', '3' ] }`). However, if
613
+ * only one value is present (e.g.: `/foo?bar=1`) then the value is treated as single
614
+ * value (e.g.: `{ foo: '1' }`).
615
+ *
616
+ * <pre>params: {
617
+ * param1: { array: true }
618
+ * }</pre>
619
+ *
620
+ * - ** squash ** - {bool|string=}: `squash` configures how a default parameter value is represented in the URL when
621
+ * the current parameter value is the same as the default value. If `squash` is not set, it uses the
622
+ * configured default squash policy.
623
+ * (See {@link ui.router.util.$urlMatcherFactory#methods_defaultSquashPolicy `defaultSquashPolicy()` })
624
+ *
625
+ * There are three squash settings:
626
+ *
627
+ * - false: The parameter's default value is not squashed. It is encoded and included in the URL
628
+ * - true: The parameter's default value is omitted from the URL. If the parameter is preceeded and followed
629
+ * by slashes in the state's `url` declaration, then one of those slashes are omitted.
630
+ * This can allow for cleaner looking URLs.
631
+ * - `"<arbitrary string>"`: The parameter's default value is replaced with an arbitrary placeholder of your choice.
632
+ *
633
+ * <pre>params: {
634
+ * param1: {
635
+ * value: "defaultId",
636
+ * squash: true
637
+ * } }
638
+ * // squash "defaultValue" to "~"
639
+ * params: {
640
+ * param1: {
641
+ * value: "defaultValue",
642
+ * squash: "~"
643
+ * } }
644
+ * </pre>
645
+ *
469
646
*
470
647
* @example
471
648
* <pre>
@@ -474,7 +651,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
474
651
* // stateName can be a single top-level name (must be unique).
475
652
* $stateProvider.state("home", {});
476
653
*
477
- * // Or it can be a nested state name. This state is a child of the
654
+ * // Or it can be a nested state name. This state is a child of the
478
655
* // above "home" state.
479
656
* $stateProvider.state("home.newest", {});
480
657
*
@@ -488,9 +665,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
488
665
* .state("contacts", {});
489
666
* </pre>
490
667
*
491
- * @param {string } name A unique state name, e.g. "home", "about", "contacts".
492
- * To create a parent/child state use a dot, e.g. "about.sales", "home.newest".
493
- * @param {object } definition State configuration object.
494
668
*/
495
669
this . state = state ;
496
670
function state ( name , definition ) {
0 commit comments