What I do is put an ng-if on the ui-view elements that hold my views, and
then just set a watch variable to true or something.

Like

  <div ng-if="app.loaded">
    <div ui-view="header"></div>
  </div>

Then in the top-level app controller I have some async code that does stuff
to log the user in either using stored credentials or initiating a login
flow, but when the login is completed, I set app.loaded to true. With
ui-router at least, this delays instantiation of any ui-view controllers
until the kickoff code has been run (which is useful, because that kickoff
code runs async and therefore can't easily be shoved into a run block as
far as I understand).

Then I let angular deal with broadcasting and whatnottery. It's really true
that 90% or more of what people want to do imperatively with events and
other stuff can be done declaratively in HTML templates instead.

e


On Fri Dec 12 2014 at 2:14:17 PM Gary <[email protected]> wrote:

> So it seems like if I "rebroadcast" an event from the main page ("home")
> the partial controller is catching that event:
> homepage view:
>  //Catch the UserInfoSynched event
>         $rootScope.$on('UserInfoSynched', function (e, obj) {
>             $timeout(function () {
>                 //Update the list of yard sale the user belows to
>                 $scope.$broadcast("TestBroadcast", "here");
>
>             });
>         });
>
> Then in the partial views:
> $scope.$on("TestBroadcast", function (e, data) {
>             console.log("In MyPartial1Controller");
>         });
>
> Seems to work like that.  Is that the only way to get something like this
> to work?  Or am I missing a more obvious way?
>
> Thanks!
>
>
> On Friday, December 12, 2014 4:48:50 PM UTC-5, Gary wrote:
>>
>> Hello all,
>>   When a user first enters my app, they are automatically logged in, at
>> this time the user json object is populated when then fires a
>>  $rootScope.$broadcast("UserInfoSynched") message.  At this time, the
>> home page starts to paint.
>> I built a very simple dynamic directive that based on the type displays a
>> different panel display:
>>
>> app.directive("panelDisplay", function ($rootScope, $compile) {
>>     return {
>>         restrict: 'E',
>>         templateUrl: function(elem, attr){
>>             return "/Content/views/partial/"+ attr.type + "Display.html";
>>         }
>>     };
>> });
>>
>> Each panel display has it's own controller.  Within that controller, I
>> would like the broadcast "UserInfoSynched" message caught, which would then
>> paint the panel with the correct user info.  The panel is displayed
>> correctly, but it never goes into my $rootScope.$on("UserInfoSynched",
>> ....) area to fire the call to get the user information needed.
>>
>> Here is one of the partial panel controllers:
>> appCtrls.controller('MyItemsController', ['$rootScope', '$scope',
>> '$filter', 'NotifyService', 'SessionService','UtilityService',
>>     function ($rootScope, $scope, $filter, notify, session, utils) {
>>         var _my_product_list = [];
>>         var _scrnType = utils.screenType();
>>         var _isLoaded = false;
>>
>>         $scope.MyProducts = function () {
>>             return _my_product_list;
>>         };
>>
>>         //Events
>>
>>         //If the window is resized to a larger size and it hasn't been
>> loaded yet, then load the items
>>         $(window).on("resize", function () {
>>             if (!_isLoaded && _scrnType == utils.screenSize.Desktop ||
>> _scrnType == utils.screenSize.lgDesktop) {
>>                 _getMyItemsForSale();
>>                 $scope.$apply();
>>             }
>>         });
>>
>>
>>         //Catch the UserInfoSynched event
>>         $rootScope.$on('UserInfoSynched', function (e, obj) {
>>             $timeout(function () {
>>                 if (_scrnType == utils.screenSize.Desktop || _scrnType ==
>> utils.screenSize.lgDesktop) {
>>                     //Get the items the user has put up for sal
>>                     _getMyItemsForSale();
>>                     _isLoaded = true;
>>                 }
>>             });
>>         });
>>
>>         //Catch the OnProductsUpdated event
>>         $rootScope.$on('OnProductsUpdated', function (e, obj) {
>>             $timeout(function () {
>>                 if (_scrnType == utils.screenSize.Desktop || _scrnType ==
>> utils.screenSize.lgDesktop) {
>>                     //Get the items the user has put up for sal
>>                     _getMyItemsForSale();
>>                     _isLoaded = true;
>>                 }
>>             });
>>         });
>>
>>
>>
>>         //***************************************************
>>         //* Method to synch the product listing when needed *
>>         //***************************************************
>>         function _getMyItemsForSale() {
>>
>>             //Code in here would get all the items for the user
>>
>>         }
>>     }
>> ]);
>>
>> Thanks very much!
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to