1

I want to use an input variable and display it inside my component HTML but I can't get it to work.

I'm pretty sure I miss something important here but can't say what.

Here is my component declaration:

app.component('requestSummary', {
    templateUrl: "./Template/request-summary",
    controller: function RequestSummary() {
        var vm = this;
    },
    bindings: {
        request: "="
    }
});

The component template:

<div>
    <h1>{{ vm.request.Pnr }}</h1>
</div>

(I have also tried without the vm)

The component use:

<md-card ng-repeat="request in vm.requests">
    <md-card-content>
        <request-summary request="request"></request-summary>
    </md-card-content>
</md-card>

When I do a console.log(vm) inside the component controller, I can see my request is there:

enter image description here

But I don't know how to print it inside the HTML.

Any help is appreciated.

1 Answer 1

1

Components have an automatic default controllerAs controller with an alias of $ctrl. You need to use:

<div>
    <h1>{{ $ctrl.request.Pnr }}</h1>
</div>

And you can get rid of the var vm = this;.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.