0

I'm trying to learn about components. I have a component like this:

app.component('modal', {
    templateUrl: 'components/modal.html',
    bindings: {
        show: '<',
        title: '@',
    },
    controller: function () {}
});

This is how I use it:

<modal show="true" title="Create Campaign">Testing.</modal>

The component's content is: Testing.

And the template:

<div class="modal" ng-show="{{ $ctrl.show }}">
    <div class="modal__body">
        <div class="modal__header">
            {{ $ctrl.title }}
            <i class="fa fa-fw fa-close modal__close" data-action="close"></i>
        </div>
        <div class="modal__content"></div>

        <div class="modal__footer">
            <button class="button button--default button--ghost" data-action="close">Cancel</button>
            <button ng-disabled="!modal.createCampaign.name" class="button button--primary button--wide pull-right"
                type="submit">Create Campaign</button>
        </div>
    </div>
</div>

How I put the component's innerHTML (Testing.) to the inside of .modal__content div?

Maybe ıt can be something like:

<div class="modal__content">{{ $ctrl.body }}</div>
1
  • did you try something like <div class="modal__content" [innerHtml]="YOUR HTML"></div> ? Commented Dec 31, 2019 at 10:03

1 Answer 1

3

Use transclude option:

app.component('modal', {
    transclude: true,
    templateUrl: 'components/modal.html',
    bindings: {
        show: '<',
        title: '@',
    },
    controller: function () {}
});

In html add ng-transclude where you want the content to be added:

<div class="modal__content" ng-transclude></div>

Read more here: https://docs.angularjs.org/guide/component

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.