These are chat archives for angular/angular-2-ionic-2

1st
Apr 2015
Miško Hevery
@mhevery
Apr 01 2015 04:50
@ajoslin you may be interested in this: angular/angular#1187
Andrew Joslin
@ajoslin
Apr 01 2015 20:25
hey @mhevery - is there a way to 'broadcast' events in angular2?
when the user presses the back arrow and the previous component in the stack is shown, I want to broadcast some sort of event to the component that's being shown
ideally, the component could being shown define a method on its prototype like 'onShown() {}'
Rob Wormald
@robwormald
Apr 01 2015 20:26
yeah - we should look at the iOS type lifecycle events
Andrew Joslin
@ajoslin
Apr 01 2015 20:31
..and THIS is what inheritance is good for
class NavComponentBase {
  onShown() {
    ..stuff..
  }
  animateIn() {
    return new Promise(...stuff...)
  }
class MyComponent extends NavComponentBase {
  onShown() {
    //my custmo logic
   super.onShown()
  }
}
navController.push(MyComponent)
(the names suck, but ignore that)
Rob Wormald
@robwormald
Apr 01 2015 20:33
yeah, i think this is the way forward
Andrew Joslin
@ajoslin
Apr 01 2015 20:33
of course, with composition this would be ...
class MyComponent {
  constructor() {
    this.navigation = new NavigationThingy({ 
      onShow: () => customLogic
    })
  }
}
me no likey
sorry @mhevery - I covered up my original question. I'm gonna post it again here and not cover it up this time.
@ajoslin
hey @mhevery - is there a way to 'broadcast' events in angular2?
when the user presses the back arrow and the previous component in the stack is shown, I want to broadcast some sort of event to the component that's being shown
ideally, the component could being shown define a method on its prototype like 'onShown() {}'
Miško Hevery
@mhevery
Apr 01 2015 20:35
Can you inject the parent component and just call the onShown() method on it?
Andrew Joslin
@ajoslin
Apr 01 2015 20:35
you mean like..
class MyComponent {
  constructor(@Parent() navCtrl: NavController) {
    navCtrl.onShow(this, 'onShown')
  }
  onShown() {
    dosomething
  }
}
that is pretty nice
could be made nicer too
Miško Hevery
@mhevery
Apr 01 2015 20:38
yes,
What do you have in mind to make it nicer?
Andrew Joslin
@ajoslin
Apr 01 2015 20:39
navCtrl.for(this)
.on('show', () =>)
.on('animateIn' , () =>)
.on('...', () =>)
for would return a manager for this component in the navigation stack
someting like that
Miško Hevery
@mhevery
Apr 01 2015 20:42
Not sure how the above is simpler. you would have to inject the manager, you would have to give things names, match them....
Andrew Joslin
@ajoslin
Apr 01 2015 20:42
I was focused on making hte user only type this once
but other than that same basic idea
Andrew Joslin
@ajoslin
Apr 01 2015 20:57
@mhevery I'm getting an error when I push a component to the for loop the second time. I can make a plunkr, but maybe from this stacktrace you'll get a clue instantly?
click push, then pop, then push again, and check console
If you don't know off the top of your head what this could be, I'll make a basic plunkr and open an issue
all this is is a for loop of dynamic components, over an array of Component constructors, and the dynamic component has a setter to instantiate the Component constructor iwth a binding
Miško Hevery
@mhevery
Apr 01 2015 20:59
no idea.
Andrew Joslin
@ajoslin
Apr 01 2015 20:59
KK, figured.
trying to find the latest ng2 plunkr link
Miško Hevery
@mhevery
Apr 01 2015 20:59
seems like something did not get re-hydrated properly
Andrew Joslin
@ajoslin
Apr 01 2015 21:00
right, it's erroring from a binding in the second page
Rob Wormald
@robwormald
Apr 01 2015 22:02
Dunno the latest plunk. Think they're about to merge my bundling code, but I'll push a new build up to my CDN and link you a new plunk. Gotta grab a sandwich first
Andrew Joslin
@ajoslin
Apr 01 2015 22:02
Just got it working
but thanks
Andrew Joslin
@ajoslin
Apr 01 2015 22:10
got it reproducable in a plunkr. opened angular/angular#1201