Andrej Cimperšek Andrej Cimperšek - 1 year ago 169
TypeScript Question

Angular 2 input parameters on root directive

This example shows how to use @Input() annotation on child components. My question is how do you use it on root component? For example if you modify code on the link above:

selector: 'app',
template: `
<bank-account bank-name="RBC" account-id="4747"></bank-account>
directives: [BankAccount]
class App {
@Input() something: string;


And in html:

<app something="Test"></app>

The above example never updates something property on App component.

Answer Source

This Tobias Bosch's comment has answer on your question:

The reason why this is not working is that your index.html in which you place the <app something="Test"></app> is not an angular component. Because of this, Angular won't compile this element. And Angular does not read attribute values during runtime, only during compile time, as otherwise we would get a performance hit.

So, at this moment you can't use input parameters on root element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download