Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: emit the state/params in uiSrefStatus events #41

Closed
christopherthielen opened this issue Feb 5, 2017 · 0 comments
Closed

Feat: emit the state/params in uiSrefStatus events #41

christopherthielen opened this issue Feb 5, 2017 · 0 comments

Comments

@christopherthielen
Copy link
Member

christopherthielen commented Feb 5, 2017

This plunker shows how to respond to changes in uiSref status using the uiSrefStatus events.

https://plnkr.co/edit/PEWdPiLCYegixwdGAdb5?p=preview

@Component({
  selector: 'my-app',
  directives: [UIROUTER_DIRECTIVES],
  template: `
  <div class="nav">
    <a uiSref="hello" uiSrefActive="active" (uiSrefStatus)="updated('hello', $event)">Hello</a>
    <a uiSref="about" uiSrefActive="active" (uiSrefStatus)="updated('about', $event)">About</a>
    <a uiSref="people" uiSrefActive="active" (uiSrefStatus)="updated('people', $event)">People</a>
  </div>
  
  <ui-view></ui-view>
`})
export class App { 
  active = {
    hello: false,
    about: false,
    people: false,
  }
  
  updated(state, event) {
    console.log(state, event);
    this.active[state] = event.active;
    console.log("active states", this.active);
  }
}

It would be nice not to have to bind the sref target manually, i.e., updated($event) instead of updated('hello', $event).

We can add the sref target to the event so it can be used in a handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant