Billy,

Yes starting into angular really changes the way we think.  Timing is one
of the main challenges I've run into (if you haven't hit that issue yet,
you will), in addition to organization of code.  Angular provides an
awesome framework for structuring your app, but it does not provide a
standard way to go about achieving the result you are after.  It's great
that it's flexible, but also challenging to understand how the components
fit together.

By creating your login method in a factory or service, you can inject it
into any controller, and since it is using rootScope to broadcast, really
any controller can add a listener to react to it.  Once again, it's up to
you how to structure views and controllers.  Having the login come into the
client controller is fine since any controller (main or child or other) can
add a listener and respond.

Good luck.

Luke



On Fri, Apr 18, 2014 at 3:12 PM, Billy Figueroa
<billyj.figue...@gmail.com>wrote:

> Luke I think you just helped me realize what is going on. This entire
> issue I believe comes from the fact that I have a login drop down menu
> which can be used from ANY page using the index.html "shell" page
>
> By default the "MainController" is on every page and it seems the login
> functions which I currently have in MainController SHOULD BE in
> ClientController. The problem is that the way I have the HTML setup,
> ClientController is LOADED upton hitting a certain route. I have been
> contemplating moving the login form to its own page. I think doing this
> will solve my issue. I was already having issues with this set up before
> but I like the easyness of having a dropdown from anypage as opposed to a
> seperate page
>
> To simplify things, since this is my first angularjs app, I will remove
> the dropdown
>
> Thanks, I think this will solve the issue...I HOPE!
>
>
> On Friday, April 18, 2014 4:39:41 PM UTC-4, Luke Kende wrote:
>
>> Well, without seeing the code, it was an option that the broadcast was
>> happening before the child controller had registered the listener.  Now
>> that I see the code, that is not the case.
>>
>> So I added the factory login method on the child scope.  Now clicking the
>> button fires the broadcast and both listeners fire as well:
>> http://plnkr.co/edit/Ti2nerqta29HPH8DZTBt?p=preview
>>
>>
>>
>>
>> On Fri, Apr 18, 2014 at 11:42 AM, Billy Figueroa <figu...@gmail.com>wrote:
>>
>>> Hey what do you mean "is loaded at the time of the broadcast'
>>>
>>> I know the controller is active becasue I have some json files I am
>>> loading for drop down menus and those are all loaded, but we never go into
>>> the $scope.$on code to the console.log statement.
>>>
>>> I am trying to recreate this and this is why I dislike plunker and
>>> jsfiddle, they always give me problems..
>>>
>>> why is this not working...
>>>
>>> http://plnkr.co/edit/h3a6ZwkUF2vCy36gEPUe?p=preview
>>>
>>> I can't get the AuthFactory to work. I tried to add a button to
>>> console.log when I click but it doesnt do anything
>>>
>>>
>>> On Friday, April 18, 2014 1:45:29 AM UTC-4, Luke Kende wrote:
>>>>
>>>> This could be a timing thing.  Are you sure your listener ($scope.$on)
>>>> in client controller is loaded at the time of the broadcast? Another
>>>> console.log just before the registration may help you see if that's the
>>>> case.  I don't believe that main as parent would override the child
>>>> controllers handler, but I have had it happen in one of my directives....
>>>> you can verify by commenting out the one in main to double check.
>>>>
>>>>
>>>>
>>>> On Thursday, April 17, 2014 7:53:56 PM UTC-6, Billy Figueroa wrote:
>>>>>
>>>>> Hi All,
>>>>>
>>>>> so I have a quick issue with my controller ordering I guess.
>>>>>
>>>>> I have the following shell page layout...
>>>>>
>>>>> <html>
>>>>>    <head></head>
>>>>>    <body ng-controller="MainController">
>>>>>       <div ng-view></div>
>>>>>    </body>
>>>>> </html>
>>>>>
>>>>> I have an ng-view template that the routeProvider is loading
>>>>> (account.php) when we hit the url and load ClientController...
>>>>>
>>>>>     .when('/client/:user_id/account', {
>>>>>         templateUrl: '../MINT/views/account.php',
>>>>>         controller: 'ClientController',
>>>>>         restrict: true
>>>>>     })
>>>>>
>>>>> I also have an AuthFacotory factory where, once a user logs in and I
>>>>> get data back from my backend (PHP) I broadcast a signal to say we are
>>>>> authenticated
>>>>>
>>>>>                     if (phpData.account_type === 'client')
>>>>>                         $rootScope.$broadcast('clientAuthenticated',
>>>>> phpData);
>>>>>                     else
>>>>>                         $rootScope.$broadcast('providerAuthenticated',
>>>>> phpData);
>>>>>
>>>>> I have the following I guess "watches" both inside the MainController
>>>>> and ClientController
>>>>>
>>>>>
>>>>> <-- MainController -->
>>>>>     $scope.$on('clientAuthenticated', function(phpData) {
>>>>>         console.log("We caught the broadcast for clientAuthenticated[
>>>>> MainController]");
>>>>>     });
>>>>>
>>>>> <-- ClientController -->
>>>>>     $scope.$on('clientAuthenticated', function(phpData) {
>>>>>         console.log("We caught the broadcast for clientAuthenticated[
>>>>> ClientController]");
>>>>>     });
>>>>>
>>>>>
>>>>> I am only "catching" the one in the MainController.
>>>>>
>>>>> Based on the structure being that the ClientController is loaded as
>>>>> part of the view, I m guessing its some sort of a child of the
>>>>> MainController but why is it not "catching" that broadcast?
>>>>>
>>>>> the weird part is that I have other code in the ClientController and
>>>>> that gets executed but the console.log inside the scope statement is not
>>>>>
>>>>> I wanted to create a jsfiddle or plunker but I rarely get them working
>>>>> when I try to do it in a non global modular way like real apps are written
>>>>> i.e. var myApp = angular.module('myApp', [])
>>>>>
>>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "AngularJS" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>> topic/angular/NaBscLyPqhY/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> angular+u...@googlegroups.com.
>>> To post to this group, send email to ang...@googlegroups.com.
>>>
>>> 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 a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/NaBscLyPqhY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> angular+unsubscr...@googlegroups.com.
> To post to this group, send email to angular@googlegroups.com.
> 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 angular+unsubscr...@googlegroups.com.
To post to this group, send email to angular@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to