Ng2ViewDeclaration | ui-router-ng2
Options
Menu

Interface Ng2ViewDeclaration

Hierarchy

Index

Properties

$context: ViewContext

The context that this view is declared within.

The context that this view is declared within.

$name: string

The raw name for the view declaration, i.e., the StateDeclaration.views property name.

The raw name for the view declaration, i.e., the StateDeclaration.views property name.

$type: string

A type identifier for the View

A type identifier for the View

This is used when loading prerequisites for the view, before it enters the DOM. Different types of views may load differently (e.g., templateProvider+controllerProvider vs component class)

$uiViewContextAnchor: string

The normalized context anchor (state name) for the uiViewName

The normalized context anchor (state name) for the uiViewName

When targeting a ui-view, the uiViewName address is anchored to a context name (state name).

$uiViewName: string

The normalized address for the ui-view which this ViewConfig targets.

The normalized address for the ui-view which this ViewConfig targets.

A ViewConfig targets a ui-view in the DOM (relative to the uiViewContextAnchor) which has a specific name.

example

header or $default

The uiViewName can also target a nested view by providing a dot-notation address

example

foo.bar or foo.$default.bar

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<any>

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