You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.1 KiB

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