AngularJS diary - Day 4
ng-model of one controller from another
$broadcast to broadcast a message (or
$emit) and put listener on that message on receiver.
When to use
$broadcast and when to use
$broadcast— dispatches the event downwards to all child scopes,
$emit— dispatches the event upwards through the scope hierarchy.
In case there is no parent-child relation, use
##Making AJAX call the right way
providers for that. It’s advised not to make AJAX calls within the controller.
##Services vs Factory
In most cases, both can be used interchangably.
When you’re using
service, Angular instantiates it behind the scenes with the
new keyword. Because of that, you’ll add properties to
this and the service will return
this. When you pass the service into your controller, those properties on
this will now be available on that controller through your service. This is why
service is most suitable for generic utilities.
factory is useful for for cases like when you don’t want to expose private fields but via public methods instead. Just like a regular class object.