Ng2ViewDeclaration | UI-Router
Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Ng2ViewDeclaration

Hierarchy

  • _ViewDeclaration

Index

Properties

Properties

bindings: object

An object which maps resolve keys to component bindings.

An object which maps resolve keys to component bindings.

A property of Ng2StateDeclaration or Ng2ViewDeclaration:

When using a component declaration (component: MyComponent), each input binding for the component is supplied data from a resolve of the same name, by default. You may supply data from a different resolve name by mapping it here.

Each key in this object is the name of one of the component's input bindings. Each value is the name of the resolve that should be provided to that binding.

Any component bindings that are omitted from this map get the default behavior of mapping to a resolve of the same name.

example

$stateProvider.state('foo', {
  resolve: {
    foo: function(FooService) { return FooService.get(); },
    bar: function(BarService) { return BarService.get(); }
  },
  component: 'Baz',
  // The component's `baz` binding gets data from the `bar` resolve
  // The component's `foo` binding gets data from the `foo` resolve (default behavior)
  bindings: {
    baz: 'bar'
  }
});

app.component('Baz', {
  templateUrl: 'baz.html',
  controller: 'BazController',
  bindings: {
    foo: '<', // foo binding
    baz: '<'  // baz binding
  }
});

Type declaration

  • [key: string]: string
component: Type

The Component class to use for this view.

The Component class to use for this view.

A property of Ng2StateDeclaration or Ng2ViewDeclaration:

The component class which will be used for this view.

example

.state('profile', {
  // Use the <my-profile></my-profile> component for the Unnamed view
  component: MyProfileComponent,
}

.state('messages', {
  // use the <nav-bar></nav-bar> component for the view named 'header'
  // use the <message-list></message-list> component for the view named 'content'
  views: {
    header: { component: NavBar },
    content: { component: MessageList }
  }
}

// Named views shorthand:
// Inside a "views:" block, a Component class (NavBar) is shorthand for { component: NavBar }
.state('contacts', {
  // use the <nav-bar></nav-bar> component for the view named 'header'
  // use the <contact-list></contact-list> component for the view named 'content'
  views: {
    header: NavBar,
    content: ContactList
  }
}

Accessing Resolve Data

The component can access the Transition's Ng2StateDeclaration.resolve data in one of two ways:

1) Using Dependency Injection in the component constructor

(using Typescript)

class MyComponent {
  constructor(@Inject("myResolveData") public resolveValueA, resolveValueB: public SomeClass) {
  }
}

(using ES6/7/babel)

class MyComponent {
  static get parameters() {
    return [["myResolveData"], [MyResolveClass]];
  }
  constructor(resolveValueA, resolveValueB) {
    this.resolveValueA = resolveValueA;
    this.resolveValueB = resolveValueB;
  }
}

See also: https://github.com/shuhei/babel-plugin-angular2-annotations

2) Using a component input

Note: To bind a resolve to a component input, the resolves must provide: a string value

```js

component

() { inputs: ['resolveValueA'] } class MyComponent { myResolveValueA; @Input() resolveValueB; @Input("resolveValueC") resolveValueC;

constructor() { } } ```

Generated using TypeDoc