arnaucube
arnaucube/commonroutesAppPublic Self-hosted repository
commonroutesApp/www/lib/angular-ui-router/src/view.js
www/lib/angular-ui-router/src/view.jsRaw
 1
 2$ViewProvider.$inject = [];
 3function $ViewProvider() {
 4
 5  this.$get = $get;
 6  /**
 7   * @ngdoc object
 8   * @name ui.router.state.$view
 9   *
10   * @requires ui.router.util.$templateFactory
11   * @requires $rootScope
12   *
13   * @description
14   *
15   */
16  $get.$inject = ['$rootScope', '$templateFactory'];
17  function $get(   $rootScope,   $templateFactory) {
18    return {
19      // $view.load('full.viewName', { template: ..., controller: ..., resolve: ..., async: false, params: ... })
20      /**
21       * @ngdoc function
22       * @name ui.router.state.$view#load
23       * @methodOf ui.router.state.$view
24       *
25       * @description
26       *
27       * @param {string} name name
28       * @param {object} options option object.
29       */
30      load: function load(name, options) {
31        var result, defaults = {
32          template: null, controller: null, view: null, locals: null, notify: true, async: true, params: {}
33        };
34        options = extend(defaults, options);
35
36        if (options.view) {
37          result = $templateFactory.fromConfig(options.view, options.params, options.locals);
38        }
39        if (result && options.notify) {
40        /**
41         * @ngdoc event
42         * @name ui.router.state.$state#$viewContentLoading
43         * @eventOf ui.router.state.$view
44         * @eventType broadcast on root scope
45         * @description
46         *
47         * Fired once the view **begins loading**, *before* the DOM is rendered.
48         *
49         * @param {Object} event Event object.
50         * @param {Object} viewConfig The view config properties (template, controller, etc).
51         *
52         * @example
53         *
54         * <pre>
55         * $scope.$on('$viewContentLoading',
56         * function(event, viewConfig){
57         *     // Access to all the view config properties.
58         *     // and one special property 'targetView'
59         *     // viewConfig.targetView
60         * });
61         * </pre>
62         */
63          $rootScope.$broadcast('$viewContentLoading', options);
64        }
65        return result;
66      }
67    };
68  }
69}
70
71angular.module('ui.router.state').provider('$view', $ViewProvider);