1

Still trying to make a good transition into Angular so probably another newb-type question but please bear with me -

In Durandal/Knockout I can use the compose binding to show a view under the context of an object ie. -

<div data-bind="with: firstPerson">
    <!-- ko compose: 'views/person' --><!-- /ko -->
</div>
<div data-bind="with: secondPerson">
    <!-- ko compose: 'views/person' --><!-- /ko -->
</div>

to show the same view bound to two separate Knockout objects (observables)

But in Angular I have not found the correct way to bind everything within an element to a certain context. How can I display multiple html files with various context(s?)?

I don't think this is the ng-repeat because it is not an array of objects, it is two separate properties on the same object ie -

  1. ParentObject
    • FirstPerson
    • SecondPerson

Edit

Obviously with Durandal and Knockout I can use something like

<span data-bind="text: fullName"></span>

inside of the person view without having to define which parent it was a part of, how can this be achieved in Angular?

1 Answer 1

1

You can use ng-include to achieve that.

<ng-include ng-init="person=firstPerson"  ng-model="person" src="'/views/person.html'"/>
<ng-include ng-init="person=secondPerson" ng-model="person" src="'/views/person.html'"/>

person.html maybe look like

<div class="modal-body">
   {{person.firstName}}, {{person.lastName}}
</div>

So you can use the same model person to refer to different data model (firstPerson or secondPerson)

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.